Android & Jetpack Compose (50 Qs)•Part 3: ART Internals, Memory Leak Profiling & Production Hardening (25 - 35)
Navigation in Jetpack Compose: Type-safe navigation routes and shared element transitions.
senior LevelCode ExampleRoutingPerformanceMemory Management
In Simple Words:
Modern Compose Navigation (Navigation 2.8+) replaces fragile string URLs ("profile/{id}") with strongly typed Kotlin Serializable classes:
kotlin
@Serializable
data class ProfileRoute(val userId: String, val referralSource: String? = null)
// Navigate type-safely:
navController.navigate(ProfileRoute(userId = "1042"))
// Define destination:
composable<ProfileRoute> { backStackEntry ->
val profile: ProfileRoute = backStackEntry.toRoute()
ProfileScreen(userId = profile.userId)
}
- Provides compile-time route verification, automatic argument parceling, and native support for predictive back gestures and shared element animations.