Repository: dotnet/maui
File: src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/glide/MauiCustomTarget.java (Java)

Code before:
    @Override
    public void onLoadCleared(@Nullable Drawable placeholder) {
        if (logger.isVerboseLoggable) logger.v("onLoadCleared: " + resourceLogIdentifier);
    }

    private void post(Runnable runnable) {
        Looper looper = Looper.getMainLooper();
        if (looper.isCurrentThread()) {
            runnable.run();
            return;
        }

        Handler handler = new Handler(looper);
        handler.post(runnable);
    }

    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 (PlatformInterop.isContextDestroyed(context)) {
                if (logger.isVerboseLoggable) {
                    logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
                }
                return;
            }
            Glide
                .with(context)
                .clear(this);
        });
    }
}

Review comment (suggestion):
@copilot can you reduce the changes here, to only target fixing this stack trace:
```
java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
	at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236)
	at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110)
	at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92)
	at com.bumptech.glide.Glide.with(Glide.java:545)
	at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88)
	at com.microsoft.maui.glide.MauiCustomTarget$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
	at com.microsoft.maui.glide.MauiCustomTarget.post(MauiCustomTarget.java:75)
	at com.microsoft.maui.glide.MauiCustomTarget.clear(MauiCustomTarget.java:86)
	at com.microsoft.maui.glide.MauiCustomTarget.$r8$lambda$IYvOQogjutk8hNIBw8oqNZ8cxUU(Unknown Source:0)
	at com.microsoft.maui.glide.MauiCustomTarget$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
```
Remove the other changes.

Code after:

    @Override
    public void onLoadCleared(@Nullable Drawable placeholder) {
        if (logger.isVerboseLoggable) logger.v("onLoadCleared: " + resourceLogIdentifier);
    }

    private void post(Runnable runnable) {
        Looper looper = Looper.getMainLooper();
        if (looper.isCurrentThread()) {
            runnable.run();
            return;
        }

        Handler handler = new Handler(looper);
        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;
            }