problem with a text view

前端 未结 2 615
长发绾君心
长发绾君心 2021-01-27 12:50

I\'m reading some data like speed and curent location using a single ton class....I\'m reading them using an AsyncTask thread in a loop....:)....each time I\'m reading a new spe

2条回答
  •  花落未央
    2021-01-27 13:56

    THelper is right, you cannot do any UI operations from a different thread than the main / UI one. You can either use his solution (which works great) or, since you are already using an AsyncTask you can use the methods provided by it:

    • publishProgress
    • onProgressUpdate

    Basically, from inside your doInBackground method you call publishProgress() and the AsyncTask class handles all thread-related headaches and calls your onProgressUpdate as soon as possible, on the UI thread, ensuring that you can modify the UI (for example call setText) without any problems.

提交回复
热议问题