其他分享
首页 > 其他分享> > Android Activity onDestroy()并不总是被调用,如果被调用,则只执行部分代码

Android Activity onDestroy()并不总是被调用,如果被调用,则只执行部分代码

作者:互联网

并不总是调用onDestroy().如果被调用,则只执行部分代码.
而且大部分时间在LogCat中我只看到消息“首先调用destroy的gps状态”.这是为什么?

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(),在某些情况下,你的应用程序等进程将被直接杀死,无论如何都会绕过方法调用.

标签:ondestroy,android
来源: https://codeday.me/bug/20190917/1808753.html