rve rve - 1 month ago 12
Android Question

Is it OK to call sendBroadcast() from another thread?

I have a service which creates a thread. This thread does some work and then calls

sendBroadcast()
on the
Service
. This means
sendBroadcast()
is called from the worker thread and not from the thread the service is running in.

Is this OK or should I make sure
sendBroadcast()
is called from the same thread as the
Service
(by using
Handler
and
Runnable
) ?

I found this on stackoverflow and Dianne Hackborns post.

According to the post it should be fine. The reason I ask is because the post is 2 years old and maybe something has changed. Also I could not find anything about this in the Android documentation.

Answer

That is fine. The Broadcast is handed to the Android OS and it is actually sent using OS threads so your thread that sends it does not matter.