android.app.Application singleton实例被重新 [英] android.app.Application singleton instance gets recreated
问题描述
我使用 android.app.Application
以创建一个实例。出于某种原因,我看到的Android杀死了我的实例
和重建(电话的onCreate
)。我怎样才能阻止这种情况发生?我试着 onTerminate
和 onLowMemory
,但这些非得到前称为实例添加日志code>被杀。
请咨询。
公共类实例扩展应用{
@覆盖
公共无效的onCreate(){
super.onCreate();
} @覆盖
公共无效onTerminate(){
super.onTerminate();
Log.e(TAGonTerminate);
} @覆盖
公共无效onLowMemory(){
super.onLowMemory();
Log.e(TAGonLowMemory);
}
}
出于某种原因,我看到的Android杀死了我的实例,并重新创建(调用的onCreate)
块引用>在Android操作系统,充分预期的行为。如果您需要SMTH跟踪一些应用程序的状态,那么你就需要使用一些持久性是指:文件存储,共享preferences或ContentProvider的。有关详细信息,这在这里: http://stackoverflow.com/a/4642069/247013
I am using
android.app.Application
to create a single instance. For some reason I see Android kills myInstance
and recreate (callonCreate
). How can I stop this from happening ? I tried adding logs ononTerminate
andonLowMemory
but non of these get called beforeInstance
get killed.Please advice.
public class Instance extends Application { @Override public void onCreate() { super.onCreate(); } @Override public void onTerminate() { super.onTerminate(); Log.e(TAG, "onTerminate"); } @Override public void onLowMemory() { super.onLowMemory(); Log.e(TAG, "onLowMemory"); } }
解决方案For some reason I see Android kills my Instance and recreate (call onCreate)
That is fully expected behavior in Android OS. If you need smth to track some app's state, then you need to use some persistance means: file storage, shared preferences or ContentProvider. More details on this here: http://stackoverflow.com/a/4642069/247013
这篇关于android.app.Application singleton实例被重新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!