开发者

Android app crashing after incoming call

I've had a bug report that when a user is playing my game and an incoming call is received, after the call is finished with my app is crashing.

The problem is I've tried to recreate the error - I've been sitting here all morning running it and phoning in - and it always resumes without any problems. I can't see any error reports relating to this problem either. I've been quite exhaustive too, calling it during various stages (ie. entering highscores, on the splash screen, during gameplay) and never any problems.

It's weird because I have had this bug reported before a while ago, and then the user said it was okay now. So I guess it must be intermittent.

I'm guessing the problem is somewhere in my onCreate() method. I thought this was the entry point when resuming an app.

Does anyone have开发者_运维知识库 an idea how to debug this "blind" without a crash report?


You are probably looking for onStart rather than onCreate. Take a look at the Activity life cycle diagram in the Android Developer Reference for Activity


What do your configChanges look like in the manifest?

Make sure you handle onConfigurationChanged correctly.

Orientation changes are the cause of many similar problems.


I think I fixed this. The problem was that I was creating a new draw thread in the surfaceCreated method, without stopping the previous thread. Not good and eventually causing a exception due to out of memory. When I used the DDMS to look at the threads I could see multiple draw threads building up. In the game I could see everything slowing down each time the app is sent into the background.

This answer helped a lot with the solution programming with thread strategy

That method advocates killing the thread when sending the app into the background. In the end, though, I decided to cause the thread to pause when the app sleeps, because it seemed a more logical approach. Nothing complex other than a wait loop inside the thread.

        while (run) {
            while ( paused ) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) { }
            }

I just set paused to true on the onStop() method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜