简体   繁体   中英

Keep Android debugger alive even after device restart

I am having trouble debugging some code in my DeviceBootReceiver (handles android.intent.action.BOOT_COMPLETED intent). I want to debug this bit, but how does one keep the debugger alive, when the device reboots? Is there any hack that anyone has come across for this?

What I want to do :

  1. Start debugging app via Android Studio
  2. Power down the device
  3. Power up the device
  4. Still be able to get the debugger attached to my app when it starts to handle android.intent.action.BOOT_COMPLETED intent

Any thoughts?

  1. Open your device "developer options" settings;
  2. Scroll down to "select debug app" and make sure your app is selected there;
  3. Check the option "wait for debugger".

This will make sure that when your app is executed, for example when it receives a BOOT_COMPLETED broadcast, the debugger gets attached first.

Hope it helps.

您可以通过 adb shell 自己重新广播意图:

$ adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

It takes about 30 seconds AFTER your device becomes available for interactions for android.intent.action.BOOT_COMPLETED to be broadcast. You have enough time to start up your application and enter debug mode manually

You might want to print a timestamp to your logcat when the android.intent.action.BOOT_COMPLETED intent is received so you have a better idea of when all this happens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM