Skip to content

Keep ndk_context valid across Android activity recreation - #5862

Open
LucaCappelletti94 wants to merge 1 commit into
DioxusLabs:mainfrom
LucaCappelletti94:upstream/android-activity-context
Open

LucaCappelletti94 wants to merge 1 commit into
DioxusLabs:mainfrom
LucaCappelletti94:upstream/android-activity-context

Conversation

@LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 commented Sep 24, 2026 •

Copy link
Copy Markdown

When Android recreates the activity, for example for the asset-path change right after a fresh install, the process survives but ndk_context still points at the first activity's global ref, which wry has freed. The next asset load crashes under CheckJNI and is undefined behaviour in release.

ndk_context now holds the Application context, which lives as long as the process. manganis::android::with_activity reads a current-activity slot that dioxus-desktop updates on every activity (hence the new Android-only manganis dependency), so plugins no longer get a destroyed activity. The manifest template also declares the configuration changes the WebView applies live (smallestScreenSize, keyboard, navigation, touchscreen, density), extending #3905.

A recreated activity still shows a blank page. A stacked follow-up PR fixes that, I separated it mostly to keep this PR as small as possible.

Hopefully once rust-mobile/ndk-context#8 merges upstream, or another better solution is identified this patch can be severely trimmed and simplified.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant