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.
About This Article
DoorDash's Android Consumer app had a timing issue. The experimentation framework needed to initialize before navigation could start, but ANL's NavGraph was being created in Activity.onCreate, which happens before onResume where data actually loads.
Maria Sharkina's team moved the app startup flow into a separate task that runs outside ANL. They manually built the NavGraph and passed Intent extras with deep link IDs to the home screen after all dependencies were ready.
This fixed several problems. Back stacks no longer got corrupted by login screens staying around after navigation. Deep links worked properly for both logged-in and logged-out users. Users stopped seeing screens they shouldn't access and stopped wasting bandwidth on data they'd never use.