Android onStop times out despite doing no work

十年热恋 提交于 2019-12-11 17:24:29

问题


I'm having trouble with an app crashing when returning to the activity.

If I navigate away with the home button the phone (or emulator) onPause, onSaveInstanceState, and onStop are all called as per the lifecycle:

05-05 14:12:20.790 2043-2043/? I/myview: onPause was run
05-05 14:12:20.790 2043-2043/? I/myview: onSaveInstanceState was run
05-05 14:12:20.790 2043-2043/? I/myview: onStop was run

Code in the activity:

@Override
    protected void onPause(){
        super.onPause();
        Log.i("myview", "onPause was run");
    }

    @Override
    protected void onStop(){
        super.onStop();
        Log.i("myview", "onStop was run");
    }

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
        Log.i("myview", "onSaveInstanceState was run");
    }

However after ten seconds the following is reported:

05-05 14:12:31.420 1586-1601/? W/ActivityManager: Activity stop timeout for ActivityRecord{9d354dc0 u0 com.example.gavin.youdrowned/.MainActivity t2}
05-05 14:12:31.420 1586-1601/? I/ActivityManager: Activity reported stop, but no longer stopping: ActivityRecord{9d354dc0 u0 com.example.gavin.youdrowned/.MainActivity t2}

I'm able to navigate back to the activity, but onResume or onCreate are not called.

The app runs full screen as expected until I try to interact with it. Tap/Clicking on the screen causes the following error to occur after about 5 seconds or so:

05-05 14:12:31.420 1586-1601/? E/ActivityManager: ANR in com.example.gavin.youdrowned (com.example.gavin.youdrowned/.MainActivity)
                                                  PID: 2043
                                                  Reason: Input dispatching timed out (Waiting because the touched window has not finished processing the input events that were previously delivered to it.)
                                                  Load: 0.54 / 0.13 / 0.04
                                                  CPU usage from 2796ms to -2455ms ago:
                                                    86% 2043/com.example.gavin.youdrowned: 11% user + 74% kernel / faults: 193 minor 1 major
                                                    49% 1586/system_server: 0.1% user + 48% kernel / faults: 874 minor
                                                    2% 1162/surfaceflinger: 0% user + 2% kernel / faults: 7 minor
                                                    0.1% 1160/debuggerd: 0.1% user + 0% kernel / faults: 3473 minor 12 major
                                                    0.3% 1165/mediaserver: 0% user + 0.3% kernel / faults: 15 minor
                                                    0.3% 1173/adbd: 0% user + 0.3% kernel / faults: 216 minor
                                                    0.3% 1938/com.google.android.gms: 0% user + 0.3% kernel / faults: 62 minor
                                                    0.1% 1186/logcat: 0% user + 0.1% kernel
                                                    0.1% 1708/com.google.android.gms.persistent: 0% user + 0.1% kernel / faults: 22 minor
                                                    0.1% 1746/com.android.phone: 0.1% user + 0% kernel / faults: 98 minor
                                                   +0% 2373/com.google.android.gms.ui: 0% user + 0% kernel
                                                  71% TOTAL: 7.8% user + 63% kernel
                                                  CPU usage from 1945ms to 2451ms later:
                                                    98% 1586/system_server: 0% user + 98% kernel / faults: 1 minor
                                                      96% 1622/Thread-35: 0% user + 96% kernel
                                                      1.9% 1601/ActivityManager: 0% user + 1.9% kernel
                                                    98% 2043/com.example.gavin.youdrowned: 12% user + 86% kernel / faults: 4 minor
                                                      98% 2088/Thread-62: 12% user + 86% kernel
                                                     +0% 2401/AudioTrack: 0% user + 0% kernel
                                                    1.6% 1162/surfaceflinger: 0% user + 1.6% kernel
                                                  100% TOTAL: 6% user + 94% kernel

The onResume never being called and the onStop timeout seems to indicate the ANR error on the back of the touch event isn't the main issue, however the onStop does no work other than a log to say it was called.

I'm not sure what's causing this issue or where to look to debug it and any insight would be greatly appreciated.


回答1:


After months of on-off power guessing changing:

holder.getSurface().unlockCanvasAndPost(c);

to

holder.unlockCanvasAndPost(c);

In the code that manages screen updates seems to have fixed this problem.



来源:https://stackoverflow.com/questions/43811633/android-onstop-times-out-despite-doing-no-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!