How to debug app when it's killed

前端 未结 3 785
予麋鹿
予麋鹿 2021-01-12 17:04

My app has a bug on certain activities: when it restarts (when it\'s killed and then opened again with multitasker), it crashes. I assume it has something to do with my sing

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 17:45

    You can add the following code to the onCreate() method of your main activity:

        android.os.Debug.waitForDebugger();
    

    This will pause your app till a debugger is attached to the process.

    Then :

    • Run your app
    • Put your app in background (say, with the home button)
    • Kill the process or use an app like MemoryPump to fill the RAM and have your app killed by Android
    • Switch back to your app with the multitask pan (the app will start and wait for the debugger)
    • Attach your android studio debugger to you app (icon in the Android Studio toolbar somewhere between the 'run app' icon and the 'stop application' icon)
    • Debug your app

提交回复
热议问题