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 = getContext();
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;
}