Answers for "'startActivityForResult(android.content.Intent, int)' is deprecated"

1

'startActivityForResult(android.content.Intent, int)' is deprecated

// 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();
                    }
                }
            });

    public void openSomeActivityForResult() {
        Intent intent = new Intent(this, SomeActivity.class);
        someActivityResultLauncher.launch(intent);
    }
Posted by: Guest on June-03-2021

Code answers related to "'startActivityForResult(android.content.Intent, int)' is deprecated"

Browse Popular Code Answers by Language