I need to debug an application that have a BroadcastReceiver that triggers when the device turns on. But Android Studio loses the connection when I turn off the smartphone. How to debug in this case? There's a way to do that?
How to debug a broadcastreceiver that receive a RECEIVE_BOOT_COMPLETED intent filter?
You can test via
- Emulator, e.g. Genymotion, see How to reboot android device emulator in Genymotion
- Rooted device, using a Hot/Soft reboot (triggered by e.g.
busybox killall system_server). Most devices stay in contact with the adb server while hot booting.
You can simulate a system broadcast using ADB shell's am command in your terminal.
$ adb shell $ am broadcast -a android.intent.action.BOOT_COMPLETED
Your emulator/device will be rebooted while it still connected with Android Monitor. Note that you cannot simulate Local broadcast, though.