attachActivity

fun attachActivity(activity: Activity)

Provides the current foreground Activity to Clerk explicitly.

Useful for framework integrations — e.g. React Native bridges, plug-in SDKs, or any host that calls initialize with a non-Activity Context after the host Activity has already passed Activity.onResume. In that case the Application.ActivityLifecycleCallbacks registered by initialize miss the initial resume, leaving Clerk's tracked activity null — which makes the first Credential Manager call (Google sign-in, passkeys) fail with a MissingActivity error until the user backgrounds and foregrounds the app.

Calling this with the current Activity immediately after initialize eliminates that gap. Subsequent activity changes are still observed via the registered lifecycle callbacks; this method only seeds the initial value.

Parameters

activity

The current foreground Activity. Held as a WeakReference so it can still be garbage-collected when destroyed.