Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActivityResult API unresolved reference error registerForActivityResult

I am trying to use ActivityResult APIs as stated here ActivityResult APIs

But it is giving unresolved reference error.

enter image description here

I am using following dependencies

api 'androidx.activity:activity:1.1.0'
api 'androidx.activity:activity-ktx:1.1.0'
api 'androidx.fragment:fragment:1.2.5'
api 'androidx.fragment:fragment-ktx:1.2.5'
like image 896
Krishna Meena Avatar asked Jul 24 '20 04:07

Krishna Meena


2 Answers

As per the Getting a result from an activity guide:

it is strongly recommended to use the Activity Result APIs introduced in AndroidX Activity 1.2.0-alpha02 and Fragment 1.3.0-alpha02.

So using the stable versions will not include those APIs. The latest versions of each is alpha07, which would mean your dependencies would be:

api 'androidx.activity:activity-ktx:1.2.0-alpha07'
api 'androidx.fragment:fragment-ktx:1.3.0-alpha07'

NOTE: your activity must extend from ComponentActivity, which was introduced in AppCompat 1.1.0 and includes the registerForActivityResult() API

like image 138
ianhanniballake Avatar answered Nov 18 '22 11:11

ianhanniballake


try this one new version is come.

 implementation 'androidx.activity:activity-ktx:1.3.1'
like image 23
Najib.Nj Avatar answered Nov 18 '22 09:11

Najib.Nj