replacement of startactivityforresult
public void openActivityForResult() {
//Instead of startActivityForResult use this one
Intent intent = new Intent(this,OtherActivity.class);
someActivityResultLauncher.launch(intent);
}
//Instead of onActivityResult() method use this one
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// Here, no request code
Intent data = result.getData();
doSomeOperations();
}
}
});
Run code snippet