Domanda

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.

È stato utile?

Soluzione

 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...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top