📜  Android Studio startActivityForResult depreciated - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:34.528000             🧑  作者: Mango

代码示例1
// You can do the assignment inside onAttach or onCreate, i.e, before the activity is displayed
    ActivityResultLauncher someActivityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            new ActivityResultCallback() {
                @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);
    }