Implementing the Android Navigation Library
Article Summary
Maria Sharkina from DoorDash discovered that Android's Navigation Library has a critical flaw: it forces navigation before your app is ready. Here's how her team solved it without breaking deep links or the back button.
When rewriting the DoorDash Android Consumer app, the team hit a wall with Android Jetpack's Navigation Library. The framework's recommended approach for conditional navigation created three major problems: unauthorized users briefly saw screens they shouldn't access, authentication logic spread across multiple destinations, and the app couldn't wait for critical dependencies to initialize before navigating.
Key Takeaways
- ANL executes navigation in onCreate, before dependencies can initialize in onResume
- Replacing NavGraph or start destination both broke back navigation
- Solution: Extract app start flow into separate task, initialize ANL later
- Deep links work by passing Intent extras to ANL starting point
- Approach prevents wasted network bandwidth and inconsistent user experiences
DoorDash solved ANL's premature navigation by moving the start flow to a separate task, ensuring dependencies initialize and users authenticate before the Navigation Library takes over.