2

当我打电话mPickFromGalleryLauncher.launch(PICK_FROM_GALLERY_INPUT)画廊打开。如果在图库中我按后退按钮应用程序已关闭。

如何从画廊返回 Fragment?应用程序使用带有 Android 导航组件的 SingleActivity 模式。

我的片段:

class ImagesFragment : Fragment(R.layout.fragment_images) {

    private val mPickFromGalleryLauncher by uiLazy {
        registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
            // handle uri
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        pickFromGalleryButton.setOnClickListener {
            mPickFromGalleryLauncher.launch("image/*")
        }
    }

}
4

0 回答 0