Because startActivityForResult is deprecated.
So I replace startActivityForResult to registerForActivityResult
This is my 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();
}
}
});
Because i call to multi Activity:
Old Version:
Intent myinten = new Intent(MainActivity.this, MainActivity2.class);
startActivityForResult(myinten, 111);
Intent myinten = new Intent(MainActivity.this, MainActivity3.class);
startActivityForResult(myinten, 222);
New Version:
Intent myinten = new Intent(MainActivity.this, MainActivity2.class);
someActivityResultLauncher.launch(myinten);
Intent myinten = new Intent(MainActivity.this, MainActivity3.class);
someActivityResultLauncher.launch(myinten);
Can we to send & get "requestCode" with "registerForActivityResult"?