onDestroy()
并不总是被调用。如果调用,则只执行部分代码。在LogCat 中,大多数时候我只看到消息“gps state on destroy called first”。这是为什么呢?
protected void onDestroy() {
super.onDestroy();
Log.d("on destroy called", "gps state on destroy called first");
editor.putBoolean("gpsOn", false);
Log.d("on destroy called", "gps state on destroy called second");
editor.commit();
Log.d("on destroy called", "gps state on destroy called third");
stopRouteTracking();
Log.d("on destroy called", "gps state on destroy called fourth");
}
最佳答案
看看这个:
Activity OnDestroy never called?
还有这个:
http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29
基本上,永远无法保证会调用 onDestroy()
,并且在某些情况下,诸如您的应用之类的进程将被直接杀死,无论如何都会绕过方法调用。
关于Android Activity onDestroy() 并不总是被调用,如果被调用,只会执行部分代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18361719/