I sent “Scores Activity” to doinbackground then run a function on Scores Activity but getting
“Only the original thread that created a view hierarchy can touch its views.” on “birinci.setText(txt);” line.
what am I missing here looks using same context?
Scores Activity
{
Object[] stuff = {this.dhn, Scores.this};
ConnectXML runXML = new ConnectXML();
runXML.execute(stuff);
}
public void setScoreListUpdate(String txt)
{
birinci.setText(txt);
}
private Scores myScores;
protected String doInBackground(Object... arguments) {
myScores = (Scores)stuff[1];
myScores.setScoreListUpdate(result);
}
The error message already gives the answer: you can’t touch (edit/modify/update/etc.) any views from a thread that did not create them. Since anything that is executed in the
doInBackgrund(...)of an AsyncTask is done by a separate thread, you can’t do any direct view manipulations in there.The solution is quite simple: override the other methods an AsyncTask provides, depending on your needs. If you’re trying to update a view after all work is done, simply override
onPostExecute(...). If you want to indicate some sort of progress while the work is being done in the background, useonProgressUpdate(...). Everything in there is being executed by the main UI thread (which created all views).Please have read through the documentation on AsyncTask, since that describes the different steps and possibilities quite clearly.