安卓活动的onDestroy()并不总是打来电话,好象叫只执行部分的code并不、好象、部分、电话

2023-09-06 04:16:34 作者:没想到.

的onDestroy()并不总是被调用。如果调用,执行的code的一部分。 和大多数在LogCat中的时候,我只看到消息上摧毁GPS状态,被称为第一次。这是为什么呢?

 保护无效的onDestroy(){
    super.onDestroy();
    Log.d(关于灭称为,GPS状态上摧毁被称为第一次);

    editor.putBoolean(gpsOn,假);
    Log.d(关于灭称为,GPS状态上摧毁所谓的第二);
    editor.commit();

    Log.d(关于灭称为,GPS状态上摧毁所谓第三);
    stopRouteTracking();
    Log.d(关于灭称为,GPS状态上摧毁所谓的第四次);





}
 

解决方案

看看这个:

活动的OnDestroy从来不叫?

安卓自定义按压效果 安卓10,代号Q,吃上安卓P了吗

和这样的:

的http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29

基本上,从未有保证,的onDestroy()将被调用,并在某些情况下,如你的应用程序将被直接打死,反正绕过方法调用。

onDestroy() is not always called. If called, only part of the code is executed. And most of the time in LogCat I only see the message "gps state on destroy called first". Why is that?

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");      





}

解决方案

Take a look at this:

Activity OnDestroy never called?

And this:

http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29

Basically, there's never a guarantee that onDestroy() will be called, and in some cases processes such as your app will be killed directly, bypassing the method call anyway.

 
精彩推荐
图片推荐