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

自作多情 提交于 2019-12-03 02:27:05

问题


Since the phone restarts and thus gets disconnected from the Eclipse debugger/LogCat while it's booting up, how do I see where my boot complete broadcast receiver is crashing?

I am performing some actions in the onReceive() of my public class BootCompleteReceiver extends BroadcastReceiver { ... }

This is crashing and popping up a force close dialog when the phone boots. How do I debug this and see where the problem is?

The question holds true for debugging any BOOT_COMPLETE broadcast receivers.

Thanks!

EDIT

Yes, we can see the system logs in LogCat as the phone is booting up but my app Log.d(TAG,"Boot completed") has to wait till it (onReceive) gets triggered but by that time the app crashes because the problem is somewhere in the receiver itself. The app crashes before I can log anything. Also, I cannot use "Run in Debug mode" for a phone that's restarting...


回答1:


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




回答2:


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




回答3:


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.




回答4:


Just put to your terminal in Android Studio

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



来源:https://stackoverflow.com/questions/10086994/how-to-debug-boot-complete-broadcast-receivers-force-close-crashes

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