You cannot start a load for a destroyed activity in relativelayout image using glide
Use:
Glide.with(getApplicationContext()).load(...)
Instead of:
Glide.with(TabMorePagesDetailActivity.this).load(...)
Hope it will solve your problem~
BEWARE: See Glide image loading with application context if you decide to use applicationContext
You can simply check the context is destroyed or not manually as;
if (context == null) {
return
} else if (context !is Application) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (context is FragmentActivity) {
if ((context as FragmentActivity).isDestroyed) {
return
}
} else if (context is Activity) {
if ((context as Activity).isDestroyed) {
return
}
}
}
}
This can also be represented as a Kotlin extension function:
/**
* Return true if this [Context] is available.
* Availability is defined as the following:
* + [Context] is not null
* + [Context] is not destroyed (tested with [FragmentActivity.isDestroyed] or [Activity.isDestroyed])
*/
fun Context?.isAvailable(): Boolean {
if (this == null) {
return false
} else if (this !is Application) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (this is FragmentActivity) {
return !this.isDestroyed
} else if (this is Activity) {
return !this.isDestroyed
}
}
}
return true
}
Inspired from a GitHub thread, I am using this before loading any image
final Context context = getApplication().getApplicationContext();
if (isValidContextForGlide(context)){
// Load image via Glide lib using context
}
public static boolean isValidContextForGlide(final Context context) {
if (context == null) {
return false;
}
if (context instanceof Activity) {
final Activity activity = (Activity) context;
if (activity.isDestroyed() || activity.isFinishing()) {
return false;
}
}
return true;
}
Please do not use Glide.with(getApplicationContext())
unless you really need to, for reasons discussed here:
Glide image loading with application context
The correct answer is outlined here: https://github.com/bumptech/glide/issues/1484#issuecomment-365625087
In Kotlin, that can be written as an extension function:
fun Context.isValidGlideContext() = this !is Activity || (!this.isDestroyed && !this.isFinishing)
I have got the same issue before few days.I have solved this to passing the Application context memory behalf of current Class context memory.
May be it will help you :-
use this code
Glide.with(getApplicationContext())
.load(coverIMGurl)
.asBitmap()
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.into(new SimpleTarget<Bitmap>(500, 500) {....}
Even you are getting this issue then read this article carefully "https://github.com/bumptech/glide/issues/1097"
overview for this issue : This is an issue of Glide library.