Home > Mobile >  registerForActivityResult won't seem to import Kotlin
registerForActivityResult won't seem to import Kotlin

Time:10-20

Im trying to use the function registerForActivityResult in my android project made in android studio. But when I write "registerForActivityResult" to use the function all that is showing is create function. I thought registerForActivityResult was a remade function in Android an I don't know what to do to make it work. If any of you kind souls could help me I would deeply appreciate it, I can always gather more information if needed!

Update Im currently using the guide provided in this video. I am using android.activity.1.3.1 and the code that isn't working is this: private val signInLauncher = registerForActivityResult ( FirebaseAuthUIActivityResultContract() ) { res -> this.signInResult(res) }

CodePudding user response:

have you tried rememberLauncherForActivityResult if your are using compose?

val launcher = rememberLauncherForActivityResult(ActivityResultContracts.WhatEverYoutWant) {
    
}

CodePudding user response:

Try manually casting to ComponentActivity.

I've ended up creating an extension for this function:

fun <I, O> Activity.registerForActivityResult(
    contract: ActivityResultContract<I, O>,
    callback: ActivityResultCallback<O>
) = (this as ComponentActivity).registerForActivityResult(contract, callback)

It seems there is an open bug for AndroidStudio: Bug: unable to find registerForActivityResult on large project despite having the needed dependencies

  • Related