Android: what does "it is not allowed to update UI from a non-ui thread" mean?

StackOverflow https://stackoverflow.com/questions/20489311

  •  30-08-2022
  •  | 
  •  

문제

This works:

private class MyAsyncTask extends AsyncTask<....>{

    protected void onPostExecute(){
        // img is an ImageView
        img.setImageBitmap(bitmap);
    }
}

Sorry guys, I think my question should be more accurate if I ask " why img.setImageBitmap(bitmap) is already run on UI thread. I thought it was updating a View in the UI from the AsyncTask thread.

도움이 되었습니까?

해결책

 why img.setImageBitmap(bitmap) is already run on UI thread

Because you wrote it in onPostExecute() method of AsyncTask. In AsyncTask, the methods like onPreExecute() and onPostExecute() always run on your main UI thread, while only doInBackground() runs on a separate thread...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top