Skip to content

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

Open
rib wants to merge 1 commit intomainfrom
rib/pr/init-ndk-context-once-with-app
Open

Only init ndk-context once with an Application ref#229
rib wants to merge 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 a 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 (the currently implementation depends on having an Activity reference, even though ndk-context doesn't promise to provide an Activity as the 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
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