Glide assert: java.lang.IllegalArgumentException: You must call this method on the main thread
Update image in main ui thread
runOnUiThread(new Runnable() {
@Override
public void run() {
Glide.with(MainActivity.this)
.load("image URL")
.into(imageView);
}
});
The into(ImageView)
method of Glide
requires you to call it only on main thread, but when you pass the loading to a Timer it will be executed in a background
thread.
What you can do is to retrieve a bitmap by calling get()
instead of into()
and then set that bitmap
on the ImageView
by calling setImageBitmap()
.
Glide.with(getApplicationContext())
.load("your url")
.asBitmap()
.into(new BitmapImageViewTarget(imgView) {
@Override
protected void setResource(Bitmap resource) {
//Play with bitmap
super.setResource(resource);
}
});
You can also take a look at this document for more information.
Posting the code just in case it helps someone.
Bitmap myBitmap = Glide.with(applicationContext)
.load(yourUrl)
.asBitmap()
.centerCrop()
.into(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL)
.get()
imageView.setImageBitmap(myBitmap);