Can someone clarify the links to the Android context?

My misunderstanding continues ...

Can someone provide links for the correct use of get*Context() ? I get conflicting recommendations for using getBaseContext() , getApplicationContext() and getContext() , and I understand that using this is a convenience for get*Context() . I would like to study in more detail what Dalvik intends to use for his object and access methods.

I had code scans that changed my calls to getBaseContext() to getApplicationContext() , now I see suggestions for using this.

+4
source share
1 answer

http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

Read this article. It describes why we should use getApplicationContext() rather than Activity this

This is a summary of the article:

So, to avoid contextual memory leaks, remember the following:

  • Do not keep long-term references to context activity (a reference to an activity must have the same life cycle as the activity itself).
  • Try using contextual application instead of contextual activity
+1
source

All Articles