I implemented a camera feature using Jetpack Compose. Here is my current implementation:
ViewModel:
var originImageUri = mutableStateOf<Uri?>(null)
private set
View:
var capturedImageUri by pixelConvertViewModel.originImageUri
Get URI:
LaunchedEffect(navController.currentBackStackEntry) {
navController.currentBackStackEntry?.savedStateHandle?.get<Uri>("capturedImageUri")?.let {
println("capturedImageUri is $it")
// capturedImageUri = it
pixelConvertViewModel.saveOriginUrl(it)
}
}
When I take a picture and return to the current screen, capturedImageUri
has a value momentarily but then becomes null. Visually, the image appears for a moment and then disappears. If I reopen the camera screen and return, the image appears for a moment and then disappears again. The capturedImageUri
can be printed but then becomes null.
I am using Jetpack Compose’s NavController
. How can I ensure that pixelImageBitmap
is persisted?
I have try:
var capturedImageUri by rememberSaveable { mutableStateOf<Uri?>(null) }
init it in view but nothing change,Image can be display,but uri has been null,when I update view,the image dismiss
Lession Ryu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.