BroadcastReceiver ANR

1,420 views
Skip to first unread message

Eason

unread,
Apr 26, 2012, 11:04:54 PM4/26/12
to android-...@googlegroups.com
I'm told that a BroadcastReceiver hasn't finished executing within 10 seconds that will trigger ANR. I have done a test about this on ics4.0. When I dynamically register an instance of BroadcastReceiver with Context.registerReceiver(), I write a function expense time more than 10 seconds in onReceive() , if I do nothing, just waiting it run the function, it won't trigger ANR. And I resgister a BroadcastReceiver in AndroidManifest.xml, do the same thing above, it will triggle ANR.Why? What's the difference? 

Dianne Hackborn

unread,
Apr 27, 2012, 7:53:52 PM4/27/12
to android-...@googlegroups.com
If you are using registerReceiver() and not sending an ordered broadcast and there are no other receivers that are found through the manifest, then the broadcast will be sent to your registered receiver and the activity manager will never care about a response.

Even so, if you are spending more than 5 minutes in onReceive(), you are still blocking the main UI thread so other things may be happening that cause an ANR at that point (the user sending input events, the system trying to launch other components in the process, etc).

On Thu, Apr 26, 2012 at 8:04 PM, Eason <maogu...@gmail.com> wrote:
I'm told that a BroadcastReceiver hasn't finished executing within 10 seconds that will trigger ANR. I have done a test about this on ics4.0. When I dynamically register an instance of BroadcastReceiver with Context.registerReceiver(), I write a function expense time more than 10 seconds in onReceive() , if I do nothing, just waiting it run the function, it won't trigger ANR. And I resgister a BroadcastReceiver in AndroidManifest.xml, do the same thing above, it will triggle ANR.Why? What's the difference? 

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/-uzMTrEgPu0J.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages