Can someone clarify Android context references?

后端 未结 1 1983
难免孤独
难免孤独 2021-01-19 17:14

My misunderstanding continues ...

Can anyone cite references for the proper use of get*Context()? I get conflicting recommendations about using g

相关标签:
1条回答
  • 2021-01-19 17:27

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

    Read this article. It describe why we should use getApplicationContext() rather than Activity's this

    This is summary of the article:

    In summary, to avoid context-related memory leaks, remember the following:

    • Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)
    • Try using the context-application instead of a context-activity
    0 讨论(0)
提交回复
热议问题