A proposal to replace the traditional multi-backstack pattern in Jetpack Compose Navigation 3 with a 'Segmented Single Stack' approach. Instead of maintaining multiple independent stacks for bottom navigation tabs, the author suggests using a single MutableStateList where each tab root acts as a marker/anchor. Switching tabs becomes a simple list reordering operation ('bring to top'), making app state fully transparent and debuggable. The post addresses ViewModel lifecycle concerns, noting that ViewModels stay alive as long as their entries remain in the list, and persistent data should live in repositories or parent-scoped ViewModels.
Table of contents
Stop Fighting the Framework, Start Managing the List.The Naturalness of a Single Stack1. Visualizing the Structure: Hidden vs. Visible StateGet chanzmao ’s stories in your inbox2. Implementation: “Bring to Top” Logic3. The Elephant in the Room: ViewModel Lifecycle4. Why This Wins5. Conclusion: What do you think?Jetpack Compose State Survival Guide: From remember to rememberNavBackStackStop Fighting Multiple BackStacks in Jetpack Compose Navigation3Sort: