可有人澄清Android的情况下引用?

问题描述:

我的误会继续...

任何人都可以举出的正确使用中得到参考*上下文()?我得到关于使用相互矛盾的建议 getBaseContext() getApplicationContext()的getContext()键,我的理解是,使用是一个方便获得*上下文()。我想更具体的是什么的Dalvik是有意的目的和访问方法研究。

Can anyone cite references for the proper use of get*Context()? I get conflicting recommendations about using getBaseContext(), getApplicationContext() and getContext() and my understanding is that using this is a convenience to get*Context(). I would like to study more specifically of what Dalvik is intending its object and access methods.

我有code评论说改变了我的电话,以 getBaseContext() getApplicationContext(),现在我看到建议使用此功能。

I had code reviews that changed my calls to getBaseContext() to getApplicationContext(), now I am seeing suggestions to use this.

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

阅读这篇文章。这说明我们为什么要使用 getApplicationContext(),而不是活动的

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

这是文章概要:

总之,为了避免上下文相关的内存泄漏,请记住以下几点:

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

  • 请不要保持长寿的参考上下文活动(参考活动应具有相同的生命周期的活动本身)
  • 尝试使用上下文应用程序而不是一个上下文活动