Skip to content

Only init ndk-context once with an Application ref#229

Merged
rib merged 1 commit intomainfrom
rib/pr/init-ndk-context-once-with-app
Mar 10, 2026
Merged

Only init ndk-context once with an Application ref#229
rib merged 1 commit intomainfrom
rib/pr/init-ndk-context-once-with-app

Conversation

@rib
Copy link
Member

@rib rib commented Mar 5, 2026

Instead of initializing ndk-context with an Activity reference (for the android.context.Context subclass) we now initialize with an android.app.Application reference (also an android.context.Context subclass).

The benefit of this is that we can strictly initialize ndk-context once (via a OnceLock) so there's no risk of an ndk-context panic in case an application starts more than one Activity within the same process.

For reference; I've tested this change in conjunction with amodm/webbrowser-rs#111 to confirm that the webbrowser crate can be made to work with an Application or Activity reference (prior to the 1.2 release it expects an Activity and >= 1.2 it can handle an Activity or Application Context).

Fixes: #58
Fixes: #228

Instead of initializing `ndk-context` with an `Activity` reference (for
the `android.context.Context` subclass) we now initialize with
an `android.app.Application` reference (also an
`android.context.Context` subclass).

The benefit of this is that we can strictly initialize `ndk-context`
once (via a `OnceLock`) so there's no risk of a panic in case an
application starts more than one Activity within the same process.

Fixes: #58
Fixes: #228
@rib rib merged commit 0f49d96 into main Mar 10, 2026
7 checks passed
@rib rib deleted the rib/pr/init-ndk-context-once-with-app branch March 10, 2026 13:41
@rib rib mentioned this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant