Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 593
Carl Manaster Avatar asked Dec 07 '22 14:12

Carl Manaster


2 Answers

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.

like image 72
CommonsWare Avatar answered Dec 09 '22 05:12

CommonsWare


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

like image 28
David Scott Avatar answered Dec 09 '22 05:12

David Scott