Skip to content Skip to sidebar Skip to footer

How To Debug Ondestroy(), Android System Kills App While Paused In Debugger

I have a bug I'm trying to analyze that occurs when the Activity's onDestroy() method is called after hitting the back button. I've put breakpoints in the offending code (using Ec

Solution 1:

A workaround that I found is to put a startActivity() call into onDestroy() (before super.onDestroy()) that starts a dummy instance of the Activity, just to keep the app alive. The Android system won't garbage collect the app thread because there is still an Activity running within it (the new dummy Activity). This in turn allows you to debug things because the debugger's connection to thread won't be lost.

If the phone pops up a dialog saying the app is not responding (Force Close or Wait), don't click Wait, just leave it alone. It seemed that clicking Wait caused the app thread to be killed and a new thread was created for the dummy Activity.

Solution 2:

You can try a breakpoint on super.onDestroy(), but I suspect you'll have the same luck. :(

Android won't let you linger in onDestroy, it will timeout, so try to accomplish your shutdown more quickly. onDestroy() is intended only for freeing resources and isn't always called before termination; data should be persisted in onPause() or onStop(). https://developer.android.com/training/basics/activity-lifecycle/stopping.html

Addendum: Other options include using a background service for some of the work or to manually handle the back button to give yourself more time, but it could negatively impact user experience.

http://www.stanford.edu/class/cs193a/03/

sent from my phone, please cut my thumbs some slack.

Post a Comment for "How To Debug Ondestroy(), Android System Kills App While Paused In Debugger"