Skip to content

Comments

Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities#29780

Merged
PureWeen merged 13 commits intoinflight/currentfrom
copilot/fix-29699
Jan 16, 2026
Merged

Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities#29780
PureWeen merged 13 commits intoinflight/currentfrom
copilot/fix-29699

Conversation

Copy link
Contributor

Copilot AI commented Jun 2, 2025

Problem

Random crashes occurring on Android devices with the error:

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)

This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed.

Solution

Added defensive context destruction check in MauiCustomTarget.clear() before calling Glide.with(context).clear(this).

Key Changes:

  1. Added private context lifecycle validation methods to MauiCustomTarget:

    • isContextDestroyed() - Checks if context/activity is destroyed or finishing
    • getActivity() - Safely extracts Activity from Context (handles ContextWrapper chains)
  2. Protected MauiCustomTarget.clear() operation:

    • Added context check before calling Glide.with(context).clear(this)
    • Includes verbose logging when the clear operation is skipped due to destroyed context

Behavior:

  • When context is destroyed, clear() returns early without attempting to call Glide
  • Matches Glide's own validation logic: activity.isFinishing() || activity.isDestroyed()
  • Logs a debug message when clear is skipped (if verbose logging is enabled)

Example of the fix:

private void clear() {
    post(() -> {
        if (isContextDestroyed(context)) {
            if (logger.isVerboseLoggable) {
                logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
            }
            return;
        }
        Glide
            .with(context)
            .clear(this);
    });
}

This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality.

Fixes #29699.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Copilot AI changed the title [WIP] java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide Fix Glide IllegalArgumentException for destroyed activities in image loading Jun 2, 2025
Copilot AI requested a review from jfversluis June 2, 2025 12:45
@jfversluis
Copy link
Member

jfversluis commented Jun 2, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we add a test for this issue?

…fy patterns

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 2, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-7.6.1-all/942lu1p9i6mhoyzmt401s4g74/gradle-7.6.1/lib/gradle-launcher-7.6.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.6.1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figure out how we add a test for this issue. We don't want it to regress in the future.

Copy link
Contributor Author

Copilot AI commented Jun 2, 2025

How do we add a test for this issue?

Testing this requires adding Java unit tests to the AndroidNative module since the fix is in Java code. Here's the approach:

  1. Add test dependencies to maui/build.gradle:

    dependencies {
      testImplementation 'junit:junit:4.13.2'
      testImplementation 'org.mockito:mockito-core:4.8.0'
      testImplementation 'org.robolectric:robolectric:4.9'
      testImplementation 'androidx.test:core:1.5.0'
    }
  2. Create test source structure: src/test/java/com/microsoft/maui/

  3. Test the helper methods:

    • isContextDestroyed() with various mock contexts (destroyed activity, finishing activity, null context, lifecycle states)
    • getActivity() with different context types (Activity, ContextWrapper chains, null)
  4. Test the image loading methods:

    • Verify early return with destroyed contexts
    • Verify callback receives onComplete(false, null, null)
    • Verify normal operation with valid contexts
  5. Key test scenarios:

    • Destroyed FragmentActivity
    • Finishing Activity
    • DESTROYED lifecycle state
    • Exception during lifecycle check
    • ContextWrapper chains leading to destroyed activities

Would you like me to implement these tests? The current fix can be verified manually by simulating app backgrounding/foregrounding scenarios that trigger activity destruction during image loads.

@jonathanpeppers
Copy link
Member

Can we add the tests in C# with existing projects?

I'm not sure we want to add a new Java test project.

…tests

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 2, 2025

Figure out how we add a test for this issue. We don't want it to regress in the future.

Added comprehensive unit tests in PlatformInteropContextDestructionTest.java that verify the defensive context destruction checks. Tests cover all public image loading methods with null, destroyed, and finishing contexts to ensure callbacks are properly invoked with onComplete(false, null, null) and prevent regression. Also added test dependencies to build.gradle. Commit b28e6fb

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-7.6.1-all/942lu1p9i6mhoyzmt401s4g74/gradle-7.6.1/lib/gradle-launcher-7.6.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.6.1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@MitchBomcanhao
Copy link

MitchBomcanhao commented Jan 13, 2026

Is someone able to share a stack trace? The problem with this fix, is I don't really have any proof it fixes anything.

If I had a stack trace that even goes into the Java code this PR changes, that would be a different story, thanks!

@jonathanpeppers which trace are you after? there are plenty posted between this PR page and the originating issue page that reference the java code. personally I've not been able to reproduce the original issue (so I can't try any fixes), but we do see it user logs.

@jonathanpeppers
Copy link
Member

It's a long thread, but the one relevant one I see is:

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)

We could try the fix in simply MauiCustomTarget.java for now. If you have a different spot than this, please comment.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title Fix Glide IllegalArgumentException for destroyed activities in image loading Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities Jan 13, 2026
Copilot AI requested a review from jonathanpeppers January 13, 2026 20:47
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now looks reasonable to fix this:

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)

Assuming CI is green, can we put this on the inflight PR? @PureWeen

@MitchBomcanhao
Copy link

@jonathanpeppers did you read the original bug that is linked to this PR?

in there you can see stuff like

Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:9079)
at android.app.Activity.performCreate(Activity.java:9057)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

this is what I get in my error reports

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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
at mono.java.lang.RunnableImplementor.n_run(RunnableImplementor.java)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
at android.os.Handler.handleCallback(Handler.java:995)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loopOnce(Looper.java:273)
at android.os.Looper.loop(Looper.java:363)
at android.app.ActivityThread.main(ActivityThread.java:10060)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

@PureWeen PureWeen changed the base branch from main to inflight/current January 16, 2026 17:45
@PureWeen PureWeen merged commit 115eec8 into inflight/current Jan 16, 2026
16 of 28 checks passed
@PureWeen PureWeen deleted the copilot/fix-29699 branch January 16, 2026 17:45
github-actions bot pushed a commit that referenced this pull request Jan 20, 2026
…stroyed activities (#29780)

## Problem

Random crashes occurring on Android devices with the error:
```
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)
```

This happens when Glide attempts to clear image targets using a Context
whose underlying Activity has been destroyed.

## Solution

Added defensive context destruction check in `MauiCustomTarget.clear()`
before calling `Glide.with(context).clear(this)`.

**Key Changes:**

1. **Added private context lifecycle validation methods to
MauiCustomTarget:**
- `isContextDestroyed()` - Checks if context/activity is destroyed or
finishing
- `getActivity()` - Safely extracts Activity from Context (handles
ContextWrapper chains)

2. **Protected MauiCustomTarget.clear() operation:**
- Added context check before calling `Glide.with(context).clear(this)`
- Includes verbose logging when the clear operation is skipped due to
destroyed context

**Behavior:**
- When context is destroyed, `clear()` returns early without attempting
to call Glide
- Matches Glide's own validation logic: `activity.isFinishing() ||
activity.isDestroyed()`
- Logs a debug message when clear is skipped (if verbose logging is
enabled)

**Example of the fix:**
```java
private void clear() {
    post(() -> {
        if (isContextDestroyed(context)) {
            if (logger.isVerboseLoggable) {
                logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
            }
            return;
        }
        Glide
            .with(context)
            .clear(this);
    });
}
```

This is a surgical, minimal fix that targets the specific crash location
identified in the stack trace while maintaining all existing
functionality.

Fixes #29699.

---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more <a
href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent
tips</a> in the docs.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jan 21, 2026
…stroyed activities (#29780)

## Problem

Random crashes occurring on Android devices with the error:
```
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)
```

This happens when Glide attempts to clear image targets using a Context
whose underlying Activity has been destroyed.

## Solution

Added defensive context destruction check in `MauiCustomTarget.clear()`
before calling `Glide.with(context).clear(this)`.

**Key Changes:**

1. **Added private context lifecycle validation methods to
MauiCustomTarget:**
- `isContextDestroyed()` - Checks if context/activity is destroyed or
finishing
- `getActivity()` - Safely extracts Activity from Context (handles
ContextWrapper chains)

2. **Protected MauiCustomTarget.clear() operation:**
- Added context check before calling `Glide.with(context).clear(this)`
- Includes verbose logging when the clear operation is skipped due to
destroyed context

**Behavior:**
- When context is destroyed, `clear()` returns early without attempting
to call Glide
- Matches Glide's own validation logic: `activity.isFinishing() ||
activity.isDestroyed()`
- Logs a debug message when clear is skipped (if verbose logging is
enabled)

**Example of the fix:**
```java
private void clear() {
    post(() -> {
        if (isContextDestroyed(context)) {
            if (logger.isVerboseLoggable) {
                logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
            }
            return;
        }
        Glide
            .with(context)
            .clear(this);
    });
}
```

This is a surgical, minimal fix that targets the specific crash location
identified in the stack trace while maintaining all existing
functionality.

Fixes #29699.

---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more <a
href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent
tips</a> in the docs.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Jan 23, 2026
…stroyed activities (#29780)

## Problem

Random crashes occurring on Android devices with the error:
```
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)
```

This happens when Glide attempts to clear image targets using a Context
whose underlying Activity has been destroyed.

## Solution

Added defensive context destruction check in `MauiCustomTarget.clear()`
before calling `Glide.with(context).clear(this)`.

**Key Changes:**

1. **Added private context lifecycle validation methods to
MauiCustomTarget:**
- `isContextDestroyed()` - Checks if context/activity is destroyed or
finishing
- `getActivity()` - Safely extracts Activity from Context (handles
ContextWrapper chains)

2. **Protected MauiCustomTarget.clear() operation:**
- Added context check before calling `Glide.with(context).clear(this)`
- Includes verbose logging when the clear operation is skipped due to
destroyed context

**Behavior:**
- When context is destroyed, `clear()` returns early without attempting
to call Glide
- Matches Glide's own validation logic: `activity.isFinishing() ||
activity.isDestroyed()`
- Logs a debug message when clear is skipped (if verbose logging is
enabled)

**Example of the fix:**
```java
private void clear() {
    post(() -> {
        if (isContextDestroyed(context)) {
            if (logger.isVerboseLoggable) {
                logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
            }
            return;
        }
        Glide
            .with(context)
            .clear(this);
    });
}
```

This is a surgical, minimal fix that targets the specific crash location
identified in the stack trace while maintaining all existing
functionality.

Fixes #29699.

---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more <a
href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent
tips</a> in the docs.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Jan 23, 2026
…stroyed activities (#29780)

## Problem

Random crashes occurring on Android devices with the error:
```
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)
```

This happens when Glide attempts to clear image targets using a Context
whose underlying Activity has been destroyed.

## Solution

Added defensive context destruction check in `MauiCustomTarget.clear()`
before calling `Glide.with(context).clear(this)`.

**Key Changes:**

1. **Added private context lifecycle validation methods to
MauiCustomTarget:**
- `isContextDestroyed()` - Checks if context/activity is destroyed or
finishing
- `getActivity()` - Safely extracts Activity from Context (handles
ContextWrapper chains)

2. **Protected MauiCustomTarget.clear() operation:**
- Added context check before calling `Glide.with(context).clear(this)`
- Includes verbose logging when the clear operation is skipped due to
destroyed context

**Behavior:**
- When context is destroyed, `clear()` returns early without attempting
to call Glide
- Matches Glide's own validation logic: `activity.isFinishing() ||
activity.isDestroyed()`
- Logs a debug message when clear is skipped (if verbose logging is
enabled)

**Example of the fix:**
```java
private void clear() {
    post(() -> {
        if (isContextDestroyed(context)) {
            if (logger.isVerboseLoggable) {
                logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier);
            }
            return;
        }
        Glide
            .with(context)
            .clear(this);
    });
}
```

This is a surgical, minimal fix that targets the specific crash location
identified in the stack trace while maintaining all existing
functionality.

Fixes #29699.

---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more <a
href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent
tips</a> in the docs.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
PureWeen added a commit that referenced this pull request Jan 25, 2026
## What's Coming

.NET MAUI inflight/candidate introduces significant improvements across
all platforms with focus on quality, performance, and developer
experience. This release includes 16 commits with various improvements,
bug fixes, and enhancements.


## Checkbox
- [Android] Implement material3 support for CheckBox by
@HarishwaranVijayakumar in #33339
  <details>
  <summary>🔧 Fixes</summary>

- [Implement Material3 Support for
CheckBox](#33338)
  </details>

## CollectionView
- [Android] Fixed EmptyView doesn’t display when CollectionView is
placed inside a VerticalStackLayout by @NanthiniMahalingam in
#33134
  <details>
  <summary>🔧 Fixes</summary>

- [CollectionView does not show an EmptyView template with an empty
collection](#32932)
  </details>

## Essentials
- [Windows]Fix NullReferenceException in OpenReadAsync for FileResult
created with full path by @devanathan-vaithiyanathan in
#28238
  <details>
  <summary>🔧 Fixes</summary>

- [[Windows] FileResult(string fullPath) not initialized
properly](#26858)
  </details>

## Image
- Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for
destroyed activities by @jfversluis via @Copilot in
#29780
  <details>
  <summary>🔧 Fixes</summary>

- [java.lang.IllegalArgumentException: You cannot start a load for a
destroyed activity - glide](#29699)
  </details>

## Label
- [Android] Fix for Label WordWrap width issue causing HorizontalOptions
misalignment by @praveenkumarkarunanithi in
#33281
  <details>
  <summary>🔧 Fixes</summary>

- [[Android] Unexpected Line Breaks in Android, Label with WordWrap Mode
Due to Trailing Space.](#31782)
- [Label not sized correctly on
Android](#27614)
  </details>

- Fix to Improve Flyout Accessibility by Adjusting UITableViewController
Labels by @SuthiYuvaraj in #31619
  <details>
  <summary>🔧 Fixes</summary>

- [Navigation section present under hamburger are programmatically
define as table :A11y_.NET maui_User can get all the insights of
Dashboard_Devtools](#30894)
  </details>

## Mediapicker
- [Regression][iOS] Fix MediaPicker PickPhotosAsync getting file name in
contentType property by @devanathan-vaithiyanathan in
#33390
  <details>
  <summary>🔧 Fixes</summary>

- [[iOS] MediaPicker PickPhotosAsync getting file name in contentType
property](#33348)
  </details>

## Navigation
- Fix handler not disconnected when removing non visible pages using
RemovePage() by @Vignesh-SF3580 in
#32289
  <details>
  <summary>🔧 Fixes</summary>

- [NavigationPage.Navigation.RemovePage() fails to disconnect handlers
when removing pages, unlike
ContentPage.Navigation.RemovePage()](#32239)
  </details>

## Picker
- [Android] Fix Picker IsOpen not reset when picker is dismissed by
@devanathan-vaithiyanathan in #33332
  <details>
  <summary>🔧 Fixes</summary>

- [[Android] Picker IsOpen not reset when picker is
dismissed](#33331)
  </details>

## Shell
- [iOS & Catalyst ] Fixed IsEnabled property should work on Tabs by
@SubhikshaSf4851 in #33369
  <details>
  <summary>🔧 Fixes</summary>

- [[Catalyst] TabBarBackgroundColor, TabBarUnselectedColor, and
IsEnabled Not Working as Expected in
Shell](#33158)
  </details>

- [iOS,Windows] Fix navigation bar colors not resetting when switching
ShellContent by @Vignesh-SF3580 in
#33228
  <details>
  <summary>🔧 Fixes</summary>

- [[iOS, Windows] Shell Navigation bar colors are not updated correctly
when switching
ShellContent](#33227)
  </details>

- [iOS] Fixed Shell navigation on search handler suggestion selection by
@SubhikshaSf4851 in #33406
  <details>
  <summary>🔧 Fixes</summary>

- [[iOS] Clicking on search suggestions fails to navigate to detail page
correctly](#33356)
  </details>

## Templates
- Fix VoiceOver doesnot announces the State of the ComboBox by
@SuthiYuvaraj in #32286

## Xaml
- [XSG][BindingSourceGen] Add support for CommunityToolkit.Mvvm
ObservablePropertyAttribute by @simonrozsival via @Copilot in
#33028
  <details>
  <summary>🔧 Fixes</summary>

- [[XSG] Add heuristic to support bindable properties generated by other
source generators](#32597)
  </details>


<details>
<summary>📦 Other (2)</summary>

- [XSG] Improve diagnostic reporting during binding compilation by
@simonrozsival via @Copilot in #32905
- [Testing] Fixed Test case failure in PR 33574 - [01/19/2026] Candidate
- 1 by @TamilarasanSF4853 in #33602

</details>
**Full Changelog**:
main...inflight/candidate
PureWeen pushed a commit that referenced this pull request Feb 2, 2026
…ctivities (#33805)

- [x] Analyze the issue and understand the crash from stack trace
- [x] Review PR #29780 fix pattern for destroyed activity context check
- [x] Add context destruction check in
`PlatformInterop.loadImageFromFont(Context...)` method
- [x] Add context destruction check in other `PlatformInterop` methods
that use `Glide.with(context)`:
  - [x] `loadImageFromFile(Context...)` 
  - [x] `loadImageFromUri(Context...)`
  - [x] `loadImageFromStream(Context...)`
- [x] Verify changes compile successfully
- [x] Move `isContextDestroyed` and `getActivity` methods to
`PlatformInterop` and have `MauiCustomTarget` call them
- [x] Run code review
- [x] Run CodeQL security scan
- [x] Final verification

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>java.lang.IllegalArgumentException: You cannot start a load
for a destroyed activity - glide</issue_title>
<issue_description>### Description

Random issue that I can not reproduce but happening on a small subset of
devices according to firebase

I believe a previously closed issue maybe the same thing happening:
#17549

### Steps to Reproduce

No enough information to say at this point.

### Link to public reproduction project repository

_No response_

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

7.0.92

### Affected platforms

Android

### Affected platform versions

Android 14 and up

### Did you find any workaround?

No

### Relevant log output

```shell
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
        
          Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
       at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
       at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
       at android.app.Activity.performCreate(Activity.java:9079)
       at android.app.Activity.performCreate(Activity.java:9057)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```</issue_description>

<agent_instructions>Looking at the stack trace above, it looks like the
problem started in `loadImageFromFont()`.

This PR:
* #29780

Fixes the `clear()` code path, can we apply this to the stack trace on
this issue?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@NafeelaNazhir</author><body>
This issue has been verified in Visual Studio Code 1.100.2 with MAUI
versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the
Android(14.0+) platform. Is there any specific configuration needed for
replicate the issue?

https://github.com/user-attachments/assets/2...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #29699

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Feb 2, 2026
…ctivities (#33805)

- [x] Analyze the issue and understand the crash from stack trace
- [x] Review PR #29780 fix pattern for destroyed activity context check
- [x] Add context destruction check in
`PlatformInterop.loadImageFromFont(Context...)` method
- [x] Add context destruction check in other `PlatformInterop` methods
that use `Glide.with(context)`:
  - [x] `loadImageFromFile(Context...)` 
  - [x] `loadImageFromUri(Context...)`
  - [x] `loadImageFromStream(Context...)`
- [x] Verify changes compile successfully
- [x] Move `isContextDestroyed` and `getActivity` methods to
`PlatformInterop` and have `MauiCustomTarget` call them
- [x] Run code review
- [x] Run CodeQL security scan
- [x] Final verification

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>java.lang.IllegalArgumentException: You cannot start a load
for a destroyed activity - glide</issue_title>
<issue_description>### Description

Random issue that I can not reproduce but happening on a small subset of
devices according to firebase

I believe a previously closed issue maybe the same thing happening:
#17549

### Steps to Reproduce

No enough information to say at this point.

### Link to public reproduction project repository

_No response_

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

7.0.92

### Affected platforms

Android

### Affected platform versions

Android 14 and up

### Did you find any workaround?

No

### Relevant log output

```shell
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
        
          Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
       at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
       at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
       at android.app.Activity.performCreate(Activity.java:9079)
       at android.app.Activity.performCreate(Activity.java:9057)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```</issue_description>

<agent_instructions>Looking at the stack trace above, it looks like the
problem started in `loadImageFromFont()`.

This PR:
* #29780

Fixes the `clear()` code path, can we apply this to the stack trace on
this issue?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@NafeelaNazhir</author><body>
This issue has been verified in Visual Studio Code 1.100.2 with MAUI
versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the
Android(14.0+) platform. Is there any specific configuration needed for
replicate the issue?

https://github.com/user-attachments/assets/2...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #29699

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Feb 4, 2026
…ctivities (#33805)

- [x] Analyze the issue and understand the crash from stack trace
- [x] Review PR #29780 fix pattern for destroyed activity context check
- [x] Add context destruction check in
`PlatformInterop.loadImageFromFont(Context...)` method
- [x] Add context destruction check in other `PlatformInterop` methods
that use `Glide.with(context)`:
  - [x] `loadImageFromFile(Context...)` 
  - [x] `loadImageFromUri(Context...)`
  - [x] `loadImageFromStream(Context...)`
- [x] Verify changes compile successfully
- [x] Move `isContextDestroyed` and `getActivity` methods to
`PlatformInterop` and have `MauiCustomTarget` call them
- [x] Run code review
- [x] Run CodeQL security scan
- [x] Final verification

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>java.lang.IllegalArgumentException: You cannot start a load
for a destroyed activity - glide</issue_title>
<issue_description>### Description

Random issue that I can not reproduce but happening on a small subset of
devices according to firebase

I believe a previously closed issue maybe the same thing happening:
#17549

### Steps to Reproduce

No enough information to say at this point.

### Link to public reproduction project repository

_No response_

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

7.0.92

### Affected platforms

Android

### Affected platform versions

Android 14 and up

### Did you find any workaround?

No

### Relevant log output

```shell
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
        
          Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
       at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
       at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
       at android.app.Activity.performCreate(Activity.java:9079)
       at android.app.Activity.performCreate(Activity.java:9057)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```</issue_description>

<agent_instructions>Looking at the stack trace above, it looks like the
problem started in `loadImageFromFont()`.

This PR:
* #29780

Fixes the `clear()` code path, can we apply this to the stack trace on
this issue?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@NafeelaNazhir</author><body>
This issue has been verified in Visual Studio Code 1.100.2 with MAUI
versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the
Android(14.0+) platform. Is there any specific configuration needed for
replicate the issue?

https://github.com/user-attachments/assets/2...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #29699

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Feb 13, 2026
…ctivities (#33805)

- [x] Analyze the issue and understand the crash from stack trace
- [x] Review PR #29780 fix pattern for destroyed activity context check
- [x] Add context destruction check in
`PlatformInterop.loadImageFromFont(Context...)` method
- [x] Add context destruction check in other `PlatformInterop` methods
that use `Glide.with(context)`:
  - [x] `loadImageFromFile(Context...)` 
  - [x] `loadImageFromUri(Context...)`
  - [x] `loadImageFromStream(Context...)`
- [x] Verify changes compile successfully
- [x] Move `isContextDestroyed` and `getActivity` methods to
`PlatformInterop` and have `MauiCustomTarget` call them
- [x] Run code review
- [x] Run CodeQL security scan
- [x] Final verification

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>java.lang.IllegalArgumentException: You cannot start a load
for a destroyed activity - glide</issue_title>
<issue_description>### Description

Random issue that I can not reproduce but happening on a small subset of
devices according to firebase

I believe a previously closed issue maybe the same thing happening:
#17549

### Steps to Reproduce

No enough information to say at this point.

### Link to public reproduction project repository

_No response_

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

7.0.92

### Affected platforms

Android

### Affected platform versions

Android 14 and up

### Did you find any workaround?

No

### Relevant log output

```shell
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
        
          Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
       at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
       at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
       at android.app.Activity.performCreate(Activity.java:9079)
       at android.app.Activity.performCreate(Activity.java:9057)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```</issue_description>

<agent_instructions>Looking at the stack trace above, it looks like the
problem started in `loadImageFromFont()`.

This PR:
* #29780

Fixes the `clear()` code path, can we apply this to the stack trace on
this issue?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@NafeelaNazhir</author><body>
This issue has been verified in Visual Studio Code 1.100.2 with MAUI
versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the
Android(14.0+) platform. Is there any specific configuration needed for
replicate the issue?

https://github.com/user-attachments/assets/2...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #29699

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Feb 15, 2026
…ctivities (#33805)

- [x] Analyze the issue and understand the crash from stack trace
- [x] Review PR #29780 fix pattern for destroyed activity context check
- [x] Add context destruction check in
`PlatformInterop.loadImageFromFont(Context...)` method
- [x] Add context destruction check in other `PlatformInterop` methods
that use `Glide.with(context)`:
  - [x] `loadImageFromFile(Context...)` 
  - [x] `loadImageFromUri(Context...)`
  - [x] `loadImageFromStream(Context...)`
- [x] Verify changes compile successfully
- [x] Move `isContextDestroyed` and `getActivity` methods to
`PlatformInterop` and have `MauiCustomTarget` call them
- [x] Run code review
- [x] Run CodeQL security scan
- [x] Final verification

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*

<issue_title>java.lang.IllegalArgumentException: You cannot start a load
for a destroyed activity - glide</issue_title>
<issue_description>### Description

Random issue that I can not reproduce but happening on a small subset of
devices according to firebase

I believe a previously closed issue maybe the same thing happening:
#17549

### Steps to Reproduce

No enough information to say at this point.

### Link to public reproduction project repository

_No response_

### Version with bug

9.0.70 SR7

### Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

### Last version that worked well

7.0.92

### Affected platforms

Android

### Affected platform versions

Android 14 and up

### Did you find any workaround?

No

### Relevant log output

```shell
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
        
          Caused by 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.PlatformInterop.loadImageFromFont(PlatformInterop.java:394)
       at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java)
       at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63)
       at android.app.Activity.performCreate(Activity.java:9079)
       at android.app.Activity.performCreate(Activity.java:9057)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
       at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773)
       at android.os.Handler.dispatchMessage(Handler.java:109)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8934)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```</issue_description>

<agent_instructions>Looking at the stack trace above, it looks like the
problem started in `loadImageFromFont()`.

This PR:
* #29780

Fixes the `clear()` code path, can we apply this to the stack trace on
this issue?</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@NafeelaNazhir</author><body>
This issue has been verified in Visual Studio Code 1.100.2 with MAUI
versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the
Android(14.0+) platform. Is there any specific configuration needed for
replicate the issue?

https://github.com/user-attachments/assets/2...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #29699

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-image Image loading, sources, caching platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide