Tim Malseed
12/05/2022, 3:03 AMNavType
in Jetpack Navigation.
You shouldn’t have to lean on this too often, as it’s not considered good practice to pass structured data via navigation arguments if you’re using route-based navigation. Instead, it’s better to pass an identifier for your data, and then go and retrieve it from your repository - if you can.
But, if your data isn’t uniquely-identifiable, or it only really exists at the UI layer, then there are times when it can be useful to serialize your structured data and pass it around. That’s where custom NavType
comes in handy - and there’s a little explanation of how to do it, buried in this guide to the navigation DSL:
https://developer.android.com/guide/navigation/navigation-kotlin-dsl#custom-types