I want to set bitmap for ImageView
. I have the URL from Firebase stroage, I use the BitmapFactory
to turn to picture, I need to apply it on ImageView
, I can do it with AsyncTask
but I don't know how to did it with thread or runnable.
AsyncTask
cannot use anymore in Android API 30, after I find on Internet, I find a solution that is run with thread and runnable.
These are my code that can work with AsyncTask
:
AsyncTask<Void,Void,Bitmap> work = new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... voids) {
URL url = null;
try {
url = new URL("Some URL");
} catch (MalformedURLException e) {
Log.d("Error",e.toString());
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
Log.d("Error",e.toString());
}
return bmp;
}
@Override
protected void onPostExecute(Bitmap bmp){
imageMessage.setImageBitmap(bmp);
}
};
work.execute();
I try to do it with thread and runnable but I don't know after I docode, how do I sent and apply it on ImageView
. In AsyncTask
, I can do that.