Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 活动上下文和应用程序上下文之间的区别
我想知道..Application Context和Activity Contextin之间的实际区别?Android
Application Context
Activity Context
Android
这两个让我很困惑。请帮我找出这两个的区别。??
要了解应用程序上下文和活动上下文的要点,请阅读以下内容:
只要您的应用程序处于活动状态并且不依赖于活动生命周期,应用程序上下文就会存在。如果您打算保留需要上下文的长期对象,请记住应用程序对象。您可以通过拨打电话轻松获取Context.getApplicationContext() or Activity.getApplication().
Context.getApplicationContext() or Activity.getApplication().
总之,要避免与上下文相关的内存泄漏,请记住以下几点:
1.不要保留对上下文活动的长期引用(对活动的引用应该与活动本身具有相同的生命周期)
2.尝试使用上下文应用程序而不是上下文活动
参考和更多信息