什么是 startActivityForResult deprecated solution for bottomNavigationView item selected?

问题描述 投票:0回答:1

1 我想从底部导航视图中从所选项目(在这种情况下,它是 R.id.status )中选择图像,并在名为 statusList 的回收视图中显示图像。如果不推荐使用 startActivityForResult,我该怎么做?

android deprecated bottomnavigationview startactivityforresult
1个回答
0
投票

首先你需要申报

private ActivityResultLauncher<String> imagePickerLauncher;

之后是启动图像选择器的方式

     // Launch the image picker
        imagePickerLauncher.launch("image/*");

要检索结果,请复制此代码

        // Initialize the imagePickerLauncher
        imagePickerLauncher = registerForActivityResult(new 
        ActivityResultContracts.GetContent(), uri -> {
            if (uri != null) {
                 // Do something with the selected image URI
                 // For example, add it to the RecyclerView adapter
                
             }
         });
© www.soinside.com 2019 - 2024. All rights reserved.