On Sat, Aug 20, 2011 at 7:38 AM, Ash <[email protected]> wrote:
> Assuming runOnUIThread is equivalent to AsyncTasks
> http://developer.android.com/reference/android/os/AsyncTask.html

AsyncTask is a class. runOnUiThread() is a method. You pass a Runnable
to runOnUiThread(), and if you are on a background thread, the
Runnable is posted to the main application thread's work queue for
eventual processing. Whatever is inside the run() method of the
Runnable is guaranteed to run on the main application thread.

For example, here is a listener from an AIDL-defined remote service
that uses runOnUiThread() to ensure that the events are passed to the
activity on the main application thread:

private final IScriptResult.Stub callback=new IScriptResult.Stub() {
    public void success(final String result) {
      runOnUiThread(new Runnable() {
        public void run() {
          successImpl(result);
        }
      });
    }

    public void failure(final String error) {
      runOnUiThread(new Runnable() {
        public void run() {
          failureImpl(error);
        }
      });
    }
  };

This is an instance of an anonymous inner class of the activity
itself, so successImpl() and failureImpl() are methods on the
activity.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.6 Available!

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