Launch an activity with a result in Jetpack Compose
Last updated:2024-07-10
![YouTube Channel](/img/ad.png)
In View System, we use registerForActivityResult()
to launch an activity with a result.
We use rememberLauncherForActivityResult()
for it in Jetpack Compose. Official document is here
@Composable
fun MainScreen() {
var uri by remember { mutableStateOf<Uri?>(null) }
val launcher = rememberLauncherForActivityResult(GetContent()) {
uri = it
}
Column {
Button(onClick = {
launcher.launch("image/*")
}) {
Text("Pick Content")
}
if (uri != null) {
Text("uri=${uri}")
}
}
}