Bret,

You saying that there are "multiple concurrent instances of the IntentService running" is not entirely accurate.

If you actually defined multiple services in Java / the manifest, my apologies.

If you only defined one service, then there is only one instance of the service, and any intents it receives are queued up to a thread-safe queue as soon as they are received. The worker thread (there is only one, AFAIK) then de-queues intents from this queue and processes them one by one.

So no synchronization issues there.

However, it's not out of the question that calling sendBroadcast, with it being a framework function, is only allowed from the UI thread, just like many other framework functions in Android.

Since you are able to consistently reproduce this problem in your application, I think it wouldn't hurt to run a simple experiment.

Change calls to sendBroadcast so they are made from the UI thread (e.g. obtain a Handler in your service's onCreate, then post a runnable containing the intent to be broadcast to the Handler).

Also: for the case you described, you could use a lighter-weight notification mechanism, such as ResultReceiver or Message.

-- Kostya

04.11.2010 20:54, Bret Foreman пишет:
I'm trying an experiment where an Activity makes a number of
consecutive calls to an IntentService. Each call kicks off some
background work that finishes in a few seconds. So there are multiple
concurrent instances of the IntentService running. All the instances
finish at around the same time and each one does a sendBroadcast to
return a message to the Activity that it's finished. When this
happens, about 30% of the broadcast intents never get back to the
Activity's registered receiver.

It looks as if there is some static state inside the IntentService
class that is in conflict when there are multiple invocations running
and they are all calling sendBroadcast at about the same time. In
other words, sendBroadcast appears to be non-re-entrant.

I'd like to package up this example for submission to b.android.com
but before I do, I'd like to find out a few things from this forum:

1) Is this a known bug?
2) Is this expected behavior (ie not a bug)?
3) Has anyone seen anything like this or another case where the
IntentService worked correctly when used in this way?



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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

Reply via email to