开发者

Activity Not Responding half the times it is launched

Something strange here: my Activity half of the time it is launched freezes and i get an ARN from the system.

A while ago i wrote i simple game in AndEngine + PhysicsBox2d extension, without incurring in any ANR problem. I spent last few days refactoring the code, introducing a couple of classes to handle start-up configuration and moving code to improve cohesion. Ideally no change in behaviour was implemented. however now if i open the app and close it normally, the second time I open it, the app freeze and get a force close for time out. Here is the output from the log:

09-03 19:41:40.416: ERROR/ActivityManager(138): ANR in mp.andreabarbadoro.mama (mp.andreabarbadoro.mama/.DaisyGameActivity)
09-03 19:41:40.416: ERROR/ActivityManager(138): Reason: keyDispatchingTimedOut 
09-03 19:41:40.416: ERROR/ActivityManager(138): Load: 2.77 / 2.62 / 2.35
09-03 19:41:40.416: ERROR/ActivityManager(138): CPU usage from 13439ms to 0ms ago with 99% awake:
09-03 19:41:40.416: ERROR/ActivityManager(138):   3.2% 116/akmd: 0.9% user + 2.3% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):   2% 1679/mp.andreabarbadoro.mama: 2% user + 0% kernel / faults: 3 minor
09-03 19:41:40.416: ERROR/ActivityManager(138):   1.6% 138/system_server: 1% user + 0.5% kernel / faults: 3 minor 1 major
09-03 19:41:40.416: ERROR/ActivityManager(138):   0.5% 228/com.android.launcher: 0.5% user + 0% kernel / faults: 57 minor
09-03 19:41:40.416: ERROR/ActivityManager(138):   0.6% 1697/kworker/0:1: 0% user + 0.6% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):   0% 67/yaffs-bg-1: 0% user + 0% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):   0% 1699/logcat: 0% user + 0% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138): 1.4% TOTAL: 1.2% user + 0.2% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138): CPU usage from 1542ms to 2104ms later:
09-03 19:41:40.416: ERROR/ActivityManager(138):   10% 138/system_server: 3.5% user + 7.1% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):     3.5% 173/InputDispatcher: 3.5% user + 0% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):     1.7% 149/SensorService: 1.7% user + 0% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):   3.5% 116/akmd: 0% user + 3.5% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):     3.5% 1694/akmd: 0% user + 3.5% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):  开发者_如何学运维 3.5% 1679/mp.andreabarbadoro.mama: 3.5% user + 0% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):     3.5% 1688/er$SensorThread: 1.7% user + 1.7% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138):   0.9% 1697/kworker/0:1: 0% user + 0.9% kernel
09-03 19:41:40.416: ERROR/ActivityManager(138): 10% TOTAL: 7.1% user + 3.5% kernel
09-03 19:41:50.756: WARN/ActivityManager(138):   Force finishing activity mp.andreabarbadoro.mama/.DaisyGameActivity

So, any idea where to start to look for this bug?

edit: after looking in the debug window for Activity.onDestroy method's breakpoint, i can see how after the activity dies android.hardware.sensormanager$SensorThread seem to bo still alive. Is this the normal behaviour?


You could look at /data/anr/traces.txt and refer to the main thread's stack trace. (assuming this file wasn't overwritten with new ANRs).


What are you doing on the onCreate method? It seems that you're doing some heavy stuff that should be handled in a different thread.

Without seeing the code it would be extremely hard to point you to the problem... So my best suggestion for now is to start a thread for the heavy tasks. Consider showing a splash screen / Progress dialog until the thread finishes (you can use AsyncTask for that)


Remember what the ANR means: You are blocking the main/UI-thread for a certain time (5s, see What Triggers ANR?), so that input events can't be handled correctly.

So you are probably doing some heavy work inside this thread, maybe executed from from onResume() or onRestart(). Start looking for these expensive operations and make sure you execute them in a seperate thread (e.g. via AsyncTasks). If you are not sure what is an expensive operation in your app, consider measuring with traceview. See this post on the android developers blog for a nice introduction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜