AsyncTask block UI thread and show progressbar with delay

后端 未结 3 1777
粉色の甜心
粉色の甜心 2020-12-07 02:44

My AsyncTask is blocking block button element while downloading image and progress dialog is shown with delay - its shows for a while before image is shown, but downloading

3条回答
  •  遥遥无期
    2020-12-07 03:24

    The image download is indeed executed in the background thread, but with return task.get(); you're just waiting for it to finish, and that's what's blocking your main thread.

    You should use onPostExecute() as a callback for when the task has finished, so not just to dismiss the dialog but also to do what you need with the bitmap returned by doInBackground().

提交回复
热议问题