AsyncTask will always run even if app is destroyed?

前端 未结 5 861
孤街浪徒
孤街浪徒 2020-12-31 04:36

I have an application and because you can\'t do network operations on the main thread I\'m using AsyncTask, so the question is once I execute() the

5条回答
  •  粉色の甜心
    2020-12-31 05:09

    onPostExecute() is called from the UI thread - so if the UI thread is no longer running, it will not continue to run. However doInBackGround() is ran from a separate worker thread so it will keep on until done (or if the JVM process is killed by the OS, which is also a possibility). Note that AsyncTasks are only recommended for shorter UI-bound background tasks and not long-running background work (a few seconds).

    In short, you can not assume that it will keep on and definitely not assume that it will post its progress or call onPostExecute().

提交回复
热议问题