Carl Manaster
Carl Manaster

Reputation: 40356

runOnUiThread() method for Android

I'm used to calling runOnUiThread() to ensure that a block of code gets run, well, on the UI thread. I would like the same ease to launch a block of code off the UI thread. What should that method look like?

Upvotes: 4

Views: 516

Answers (3)

Blundell
Blundell

Reputation: 76564

An alternative to ASyncTask

    new Thread(){
        public void run() {
            // Do something
        };
    }.start();

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007554

I suppose you would say the method is start():

new Thread() {
  public void run() {
    // do something
  }
}.start();

or use AsyncTask or some Executor from java.util.concurrent or whatever.

Upvotes: 9

David Scott
David Scott

Reputation: 1666

You most likely want an AsyncTask. Refer to this article: http://developer.android.com/resources/articles/painless-threading.html

Upvotes: 3

Related Questions