title: One Tap Sign in - Activity Result with Jetpack Compose
body: <p>I'm trying to integrate One Tap Sign in with Google into my app which I'm building with Jetpack Compose. I'm using startIntentSenderForResult to launch an intent, but now the problem is that I'm unable to receive activity result from my composable function. I'm using rememberLauncherForActivityResult to get the result from an intent but still not getting anywhere. Any solutions?</p>
  <p><strong>LoginScreen</strong></p>
  <pre><code>@Composable
  fun LoginScreen() {
      val activity = LocalContext.current as Activity
  
      val activityResult = remember { mutableStateOf&lt;ActivityResult?&gt;(null) }
      val launcher = rememberLauncherForActivityResult(
          ActivityResultContracts.StartActivityForResult()
      ) { result -&gt;
          val oneTapClient = Identity.getSignInClient(activity)
          val credential = oneTapClient.getSignInCredentialFromIntent(result.data)
          val idToken = credential.googleIdToken
          if (idToken != null) {
              // Got an ID token from Google. Use it to authenticate
              // with your backend.
              Log.d(&quot;LOG&quot;, idToken)
          } else {
              Log.d(&quot;LOG&quot;, &quot;Null Token&quot;)
          }
  
          Log.d(&quot;LOG&quot;, &quot;ActivityResult&quot;)
          if (result.resultCode == Activity.RESULT_OK) {
              activityResult.value = result
          }
      }
  
      activityResult.value?.let { _ -&gt;
          Log.d(&quot;LOG&quot;, &quot;ActivityResultValue&quot;)
      }
  
      Column(
          modifier = Modifier.fillMaxSize(),
          verticalArrangement = Arrangement.Center,
          horizontalAlignment = Alignment.CenterHorizontally
      ) {
          GoogleButton(
              onClick = {
                  signIn(
                      activity = activity
                  )
              }
          )
      }
  }
  
  fun signIn(
      activity: Activity
  ) {
      val oneTapClient = Identity.getSignInClient(activity)
      val signInRequest = BeginSignInRequest.builder()
          .setGoogleIdTokenRequestOptions(
              BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
                  .setSupported(true)
                  // Your server's client ID, not your Android client ID.
                  .setServerClientId(CLIENT_ID)
                  // Only show accounts previously used to sign in.
                  .setFilterByAuthorizedAccounts(true)
                  .build()
          )
          // Automatically sign in when exactly one credential is retrieved.
          .setAutoSelectEnabled(true)
          .build()
  
      oneTapClient.beginSignIn(signInRequest)
          .addOnSuccessListener(activity) { result -&gt;
              try {
                  startIntentSenderForResult(
                      activity, result.pendingIntent.intentSender, ONE_TAP_REQ_CODE,
                      null, 0, 0, 0, null
                  )
              } catch (e: IntentSender.SendIntentException) {
                  Log.e(&quot;LOG&quot;, &quot;Couldn't start One Tap UI: ${e.localizedMessage}&quot;)
              }
          }
          .addOnFailureListener(activity) { e -&gt;
              // No saved credentials found. Launch the One Tap sign-up flow, or
              // do nothing and continue presenting the signed-out UI.
              Log.d(&quot;LOG&quot;, e.message.toString())
          }
  }
  </code></pre>