How to debug onDestroy(), Android system kills app while paused in debugger

前端 未结 2 1150
闹比i
闹比i 2021-01-06 01:04

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

2条回答
  •  孤街浪徒
    2021-01-06 01:09

    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.

提交回复
热议问题