How to debug BOOT_COMPLETE broadcast receiver's “Force Close” crashes?

两盒软妹~` 提交于 2019-12-02 17:22:00

check your Intent's actions and bundles you are recieving ,they may null and can be a null pointer exception.

fklappan

As i wrote on another thread:

You can emulate all broadcast actions by connecting via adb to the device and open a device shell.

Here we go:

  • open console/terminal and navigating to /platform-tools
  • type "adb shell" or on linux/mac "./adb shell"
  • in the shell type "am broadcast -a android.intent.action.BOOT_COMPLETED" or whatever action you want to fire.

In this way you should be able to debug.

There are a bunch of nice commands coming with adb or the adb shell. Just try it

Regards Flo

EDIT: Using the above method will also reboot the device. To prevent the device from rebooting use am broadcast -a android.intent.action.BOOT_COMPLETED com.example.app. Note the suffix with the application package name to which the broadcast goes. This enables you to send the BOOT_COMPLETED intent to ONLY YOUR app for debugging purposes. – Roel van Uden

The receiver is only controlling when your code runs (i.e when the phone starts). Whilst debugging, run the code manually. You can resolve 99% of your issues this way and the remaining ones (if any) you can resolve by writing to LogCat so see what your code is doing.

Just put to your terminal in Android Studio

adb shell am broadcast -a android.intent.action.BOOT_COMPLETE

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!