Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.microsoft.maui.glide;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -80,10 +82,40 @@ private void post(Runnable runnable) {
handler.post(runnable);
}

private static boolean isContextDestroyed(Context context) {
Activity activity = getActivity(context);
if (activity != null) {
if (activity.isFinishing() || activity.isDestroyed()) {
return true;
}
}
return false;
}

private static Activity getActivity(Context context) {
if (context == null) {
return null;
}
if (context instanceof Activity) {
return (Activity) context;
}
if (context instanceof ContextWrapper) {
Context baseContext = ((ContextWrapper) context).getBaseContext();
return getActivity(baseContext);
}
return null;
}

private void clear() {
// TODO: it looks like no one is really disposing the result on C# side
// we must fix it there to release the Glide cache entry properly
post(() -> {
if (isContextDestroyed(context)) {
if (logger.isVerboseLoggable) {
logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
}
return;
}
Glide
.with(context)
.clear(this);
Expand Down
Loading