BroadcastReceiver onReceive timeout

北战南征 提交于 2019-12-03 06:55:57
Eric Levine

In order to prevent your app from force closing while you are paused on a break point during debugging, try installing the Dev Tools application and enable the Debug App setting which:

Lets you select the application to debug. You do not need to set this to attach a debugger, but setting this value has two effects:

  • It will prevent Android from throwing an error if you pause on a breakpoint for a long time while debugging.

All of the details are here: http://developer.android.com/tools/debugging/debugging-devtools.html

If you are doing something complicated in your onReceive method, then consider having your BroadcastReceiver start a Service and pass along the data it gets from within onReceive. The Service can then do the longer processing.

I encountered this problem even when in debug mode. It turns out that another broadcast was being sent and wasn't being handled because I was debugging the other broadcast on the main thread. Android considered my process to be in ANR and killed the whole process.

I had to temporarily modify the code to not call the other broadcast while doing my debugging.

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