Thanks for the links. Your code clarifies things a lot.

Thinking about Handler/HandlerThread made me wonder about something...
Activity class provides a method called runOnUIThread(), which seems
to me a very straight-forward way to execute commands emanating from
other threads, on UI thread. Is there any idisadvantage of using this
instead of Handler or HandlerThread?

On May 27, 11:26 am, Kostya Vasilyev <[email protected]> wrote:
> Agreed.
>
> If the service is local, you can just direct Java method calls to
> communicate, either your own scheme, or these guys:
>
> http://developer.android.com/reference/java/util/Observable.html
>
> But a direct Java method call won't switch threads for you.
>
> For posting an event to the UI thread, your options are limited, because the
> UI thread's loop is already implemented inside the Android framework.
> Handler is one of those options, and you might as well use it in the
> opposite direction as well, going from the UI thread to the worker thread.
>
> An nice property of Handler is that it works with Message objects, which can
> contain useful payload, including a plain Java object (no need to
> serlialize, etc., as long as you're within the same process).
>
> Here is a HandlerThread snippet from my current project:
>
> http://pastebin.com/kpSFH6Ke
>
> Clients call submitWorkItem on the UI thread, which processes them one by
> one in onWorkItem(), on the worker thread.
>
> -- Kostya
>
> 2011/5/27 Streets Of Boston <[email protected]>
>
> > Yes, that's possible. You'd have to take care of the threading issues,
> > though (avoiding race conditions or deadlocks, etc).
>
> > --
> > 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

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