When I open my application from the launcher icon, all the Navigation and ActionBar button works fine. But when I access the application from an explicit deep link, my ActionBar gets confused.
My main navigation is:
-> [TaskListFragment] -> [TaskDetailFragment]
When opening by the launcher icon, the back button shows correctly:
In my app, you can create an alarm for each task, so when the alarm rings and the user clicks on the notification, the flow is:
-> [TaskDetailFragment]
Then, it shows the wrong button:
Clicking in the drawer icon, it returns to [TaskListFragment]. The behavior is correct, but the ActionBar icon is not.
This is how I'm creating the deep link:
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.taskDetailFragment)
.setArguments(arguments)
.createPendingIntent()
Here is the complete code on GitHub.
MainActivity with all the Navigation boilerplate.
And my Navigation Graph.
I also tried several base implementation, such as Google's Sunflower and Architecture Components Sample without success.
I opened an Issue Tracker once I thought this was a bug in the library.
Actually the issue is that I'm using a ActionBarDrawerToggle
to do a custom Drawer animation and based on the developer that replied to the issue:
"[...] the Navigation documentation suggests not using ActionBarDrawerToggle at all, as transitions are handled for you"
And in the Navigation docs:
Note: When using NavigationUI, the top app bar helpers automatically transition between the drawer icon and the Up icon as the current destination changes. You don't need to use ActionBarDrawerToggle.
Once I need the ActionBarDrawerToggle
for the custom animation, I can't remove it. To fix the issue, I need to call my Drawer setup first with the ActionBarDrawerToggle
definition and then call the Navigation setup methods, like NavigationUI.setupActionBarWithNavController()
.
TL;DR
If you are using ActionBarDrawerToggle
with Jetpack Navigation
make sure that you set the ActionBarDrawerToggle
before call the Navigation
methods.