How to update ui from asynctask

后端 未结 3 585
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 07:05

I\'ve seen many examples of how to do this, but I can\'t figure how to implement it in my code.

I am using this code.
I have updated the url, so it will receive

3条回答
  •  误落风尘
    2020-11-29 07:21

    You have three protected methods in an AsyncTask that can interact with the UI.

    • onPreExecute()
      • runs before doInBackground()
    • onPostExecute()
      • runs after doInBackground() completes
    • onProgressUpdate()
      • this only runs when doInBackground() calls it with publishProgress()

    If in your case the Task runs for a lot longer than the 30 seconds you want to refresh you would want to make use of onProgressUpdate() and publishProgress(). Otherwise onPostExecute() should do the trick.

    See the official documentation for how to implement it.

提交回复
热议问题