Android jetpack compose app crashes when try to navigate from one screen to other with navArguments. Below is my code to navigate to the detail screen.
I tried to pass via navArguments but didn't succeed. I've metioned the data that I tried to pass from listing to detail screen.
Successful navigation : contact_list_detail_screen/contact={"name":"Salman","number":"+923218888888","type":"Mobile"}
Failed navigation : contact_list_detail_screen/contact={"name":"COAS","number":"03219999999","picture":"content://com.android.contacts/display_photo/216","type":"Mobile"}
Source:
ContactItem(contact) {
val contactStr = GsonBuilder().create().toJson(contact).toString()
Log.d(
"contact_path",
ScreenRoutes.ContactDetail.route.replace("{contact}", contactStr)
)
navController.navigate(
ScreenRoutes.ContactDetail.route.replace("{contact}", contactStr)
)
}
Navgraph:
composable(route = Screen.ContactDetail.route,
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(700)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(700)
)
}) { navStack ->
val viewModel = hiltViewModel<ContactViewModel>()
val contactString = navStack.arguments?.getString("contact")
val contact = GsonBuilder().create().fromJson(contactString, Contact::class.java)
ContactDetailScreen(navController, viewModel, contact)
}
and here is my Contact model:
data class Contact(
val name: String = "NA",
val number: String = "NA",
val picture: String?,
val type: String = "NA"
)