I am trying to use the new ActivityResultLauncher
Intent for activity result, when I make the second parameter callback (ActivityResultCallback
) Android Studio asks me which Class I want to import for the result and gives me 3 options.
I don´t know which one I need to use and which one is for the "old" method (startActivityForResult
).
I tried the 3 ways and they all seems to pass, but I get different errors in the Logcat for every option.
What is the correct choice?
This is the code:
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
Intent data = result.getData();
doSomeOperations();
}
}
}
);
It should be
androidx.activity.result
Sample code (in Kotlin):