registerActivityForResult unresolved reference kotlin android

445 Views Asked by At

I am using registerForActivityResult to signin using Google authentication API. For some unknown reason, the method is unresolved reference. I tried both options Appcompat and ComponentActivity.How can I resolve method registerForActivityResult? I get 'this' is not defined in this context when I use ComponentActivity

import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity

private val launcher = (this as ComponentActivity).registerForActivityResult(ActivityResultContracts.StartActivityForResult()){ result ->
    if (result.resultCode == Activity.RESULT_OK){
        val task = GoogleSignIn.getSignedInAccountFromIntent(result.data)
        handleSignInResult(task)
    }
}
0

There are 0 best solutions below