A
A
artem2021-06-30 20:24:46
Android
artem, 2021-06-30 20:24:46

Why is onActivityResult() deprecated?

Tells AndroidStudio that the onActivityResult() method has been deprecated.
Googled the new implementation:

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


How to be? Is it possible to score on obsolescence and use it further, or is it worth listening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-06-30
@arteqrt

Obviously, a new method must be used. In new versions of android, this method can be bang (or it just won’t work), and then you will rewrite with your ass on fire. So far, they just marked deprecated so that everyone would stop using it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question