If your callbacks are oneway, the easiest thing to do is put it all in a big synchronized() block. Be aware though that if the callback is into the local process, it will still be synchronous, so holding a lock while doing this can be a problem.
Usually the safest thing is to have a handler that you post a message to, which does the callbacks. Then you don't need any locking since the broadcasts are serialized by the handler. On Fri, Mar 13, 2009 at 10:55 AM, Streets Of Boston <flyingdutc...@gmail.com > wrote: > > Ah, now i get it! :-) > > Indeed, sendProgressCallback can be called from multiple threads. And > with your earlier explanation that the beginBroadcast does not do > locking (only a brief internal lock), it may explain the problem. In > other words, RemoteCallbackList is not thread-safe across multiple > calls to it. > > I should put the broadcast code inside a 'synchronized(mCallbacks) > { ... }' block or surround it with a ReentrantLock. > Or create mCallbacks instances for each possible thread and have my > listeners register with each of them. > > Thank you very much for your help. > Have a great weekend! > > On Mar 13, 12:58 pm, Dianne Hackborn <hack...@android.com> wrote: > > On Fri, Mar 13, 2009 at 7:27 AM, Streets Of Boston > > <flyingdutc...@gmail.com>wrote: > > > > > Either way, it means that the number of items in the list accessed by > > > getBroadcastItem is always equal to N. > > > The problem remains: How can getBroadcastItem(int) return null? > > > > I'm not sure what you mean by "either way" -- if you are doing this from > > multiple threads, your threads can clobber the list, which can lead to > this > > kind of problem. > > > > -- > > Dianne Hackborn > > Android framework engineer > > hack...@android.com > > > > Note: please don't send private questions to me, as I don't have time to > > provide private support. All such questions should be posted on public > > forums, where I and others can see and answer them. > > > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---