I'm trying to use the new Activity Results API to replace startActivityForResult. If I call registerForActivityResult in a Fragment everything is OK. However if I call the same method in an AppCompatActivity the IDE displays an "unresolved reference" error. Anyway the app builds with no errors an runs as expected. How to remove that "unresolved reference" error in the IDE?
I use: import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity
dependencies: "androidx.activity:activity-ktx:${versions.activity_ktx}" "androidx.fragment:fragment-ktx:${versions.fragment_ktx}"
Just struggled with this also for hours, I am using Android Studio 4.1 Beta. I think this is an IDE bug, since Gradle can build.
You can bypass this with casting to ComponentActivity at the moment:
private val requestPermission = (this as ComponentActivity).registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
}
Hopefully this is solved in the next IDE releases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With