我在返回活动时遇到应用程序崩溃的问题。
如果我使用主页按钮导航,则按照生命周期调用onPause,onSaveInstanceState和onStop上的电话(或模拟器):
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
活动中的代码:
@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");
}
然而,在十秒钟后报告以下内容:
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}
我能够导航回活动,但不会调用onResume或onCreate。
应用程序按预期运行全屏,直到我尝试与其进行交互。点击/单击屏幕会在大约5秒左右后发生以下错误:
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
onResume永远不会被调用,并且onStop超时似乎表明触摸事件背面的ANR错误不是主要问题,但onStop除了日志之外没有任何工作说它被调用。
我不确定导致此问题的原因或在哪里进行调试,我们将非常感谢任何见解。
答案 0 :(得分:0)
经过数月的开关电源猜测改变:
holder.getSurface().unlockCanvasAndPost(c);
到
holder.unlockCanvasAndPost(c);
在管理屏幕更新的代码中似乎已经解决了这个问题。