android - OnActivityResult method is deprecated, what is the alternative? - Stack Overflow

PHOTO EMBED

Sun May 01 2022 11:41:26 GMT+0000 (Coordinated Universal Time)

Saved by @darkoeller #java

public void openSomeActivityForResult() {
    Intent intent = new Intent(this, SomeActivity.class);
    someActivityResultLauncher.launch(intent);
}

// You can do the assignment inside onAttach or onCreate, i.e, before the activity is displayed
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();
                }
            }
        });

content_copyCOPY

https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative