📜  不推荐使用结果的启动活动 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:48.082000             🧑  作者: 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);
}