2
在Android應用程序中,在應用程序的整個生命週期中保留對從Context.getApplicationContext()
返回的應用程序上下文的引用是否安全?保持對Android應用程序上下文的引用是否安全?
Context ac = context.getApplicationContext();
// keep the ac reference throughout the app lifetime
在Android應用程序中,在應用程序的整個生命週期中保留對從Context.getApplicationContext()
返回的應用程序上下文的引用是否安全?保持對Android應用程序上下文的引用是否安全?
Context ac = context.getApplicationContext();
// keep the ac reference throughout the app lifetime
是的。應用程序上下文不會改變,直到應用程序被系統殺死。當應用程序被殺死時,您的變量將被清除。另一方面,它堅持活動的上下文是不安全的。
看看這個http://android-developers.blogspot.in/2009/01/avoiding-memory-leaks.html – Braj 2013-02-14 10:02:23