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
You should always post UI updates on the UIThread.
runOnUiThread(new Runnable() {
public void run() {
speed_1.setText(Integer.toString(speed));
location.setText(loc1);
}
}
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:
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.