Hi all.
We've got a pretty large app with millions of installs. What we've
noticed is that there are always ANRs reported, even in questionable
conditions. For example, we see ANRs in the most simple of broadcast
receivers, where there are only 4 lines of code, and no networking or
file IO. The code takes 10ms to complete in normal conditions
(although I've seen it as high as 60ms).
Now, BroadcastReceivers are supposed to have 10,000 milliseconds to
complete (10 seconds). And yet we _still_ see ANRs. So, I'm curious,
are we supposed to start a service for EVERY broadcast received? For
example:
@Override
public void onReceive(Context context, Intent intent)
{
Bundle extras = intent.getExtras();
if (extras != null)
{
Intent serviceIntent = new Intent(ACTION);
serviceIntent.setClass(context, TheService.class);
serviceIntent.putExtras(extras);
serviceIntent.putExtra(ORIGINAL_ACTION,
intent.getAction());
context.startService(serviceIntent);
}
}
And if we really are supposed to do this, I question the architecture
of broadcast receivers in the first place: if we need to do this, then
the system should have put them on separate threads to begin with.
On the other hand, what is the overhead of creating a new service for
every broadcast received? Let's say this broadcast is received 20
times a day, will that be a lot of extra CPU usage in order to create
new services, just to avoid the 1 out of 100,000 chance that there
could be an ANR? My initial tests showed that creating a service took
about 100ms, although I admit I'd need to run the tests thousands of
times over to get a better scientifically sound estimate.
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en