Trying to fix NetworkOnMainThreadException but gives Toast error

前端 未结 1 1041
滥情空心
滥情空心 2020-11-30 15:50

I\'m trying to fix a Thread error for one of my preferred examples from java code geeks.

Here\'s the code:

public class JsonParsingActivity extends A         


        
相关标签:
1条回答
  • 2020-11-30 16:28

    You can't do UI stuff in doInBackground(). Hence, you can't display a Toast there. You need to move this to onPostExecute() or somewhere else. Possibly onProgressUpdate()

    You could call publishProgress(results) and show the Toast in onProgressUpdate() or return results to onPostExecute() and display it there. You also have the option of sending the data back to an Activity method

    AsyncTask

    0 讨论(0)
提交回复
热议问题