DoorDash Maria Sharkina Aug 4, 2020

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

Critical Insight

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.

The article includes actual code snippets showing exactly how to implement this workaround while preserving deep link functionality.

About This Article

Problem

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.

Solution

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.

Impact

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.