0

How a can delay a method without blocking the UI thread? Say...

//this method is in the UI thread
public void doSomething() {
  myAsyncTask.execute() //its gona take like 1 or 2 sec, and keeps updating views in UI
  ... //i need to wait here for myAsyncTask finishes before the method finishes
}
Mike087
  • 486
  • 3
  • 13
  • You don't need to run such methods in the UI thread, you can run them in their own thread and when you have the result, then you can pass that to the UI – Tom Nov 25 '20 at 23:54
  • Is the onStop() method – Mike087 Nov 25 '20 at 23:56
  • already AsyncTAsk runs in background thread with code in doInBackground() – Zain Nov 25 '20 at 23:57
  • 1
    "i need to wait here for myAsyncTask finishes before the method finishes" -- sorry, that is not an option. Whatever work you want to do there should be part of the `onPostExecute()` of the `AsyncTask`. Note, though, that `AsyncTask` is deprecated. – CommonsWare Nov 26 '20 at 00:04

0 Answers0