I've got a bug that I think may be unsolvable. I'm not sure what I am doing wrong; and I suspect that perhaps I am not doing things in the correct, 'android' way.
I have a single activity app with multiple fragments and a drawerlayout & bottomnavigationview layout. I also have a settings toolbar icon on the right of the toolbar. Here is the view
The bottomnavigationview works fine with the settings icon. The problem is that when you navigate using the drawerlayout menu the fragment transaction is not added to the backstack. So when you navigate to settings from one of the drawerlayout items and then you click on the back icon it takes you back to the first page; not the correct drawerlayout navigation item you were currently on.
I saw in another post that I should use menucategory="second"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:menuCategory = "secondary">
<item android:id="@+id/registerJobOwnerFragment"
android:title="@string/str_register_as_job_poster"
android:icon="@drawable/baseline_add_box_24"
android:label="RegisterOwnerFragment"
android:menuCategory = "secondary"/>
<item android:id="@+id/postJobsFragment"
android:title="@string/str_post_a_job"
android:icon="@drawable/baseline_assignment_24"
android:label="PostAJobFragment"
android:menuCategory = "secondary"/>
<item android:id="@+id/checkMessagesFragment"
android:title="@string/str_check_messages_drawer_text"
android:icon="@drawable/baseline_assignment_24"
android:label="CheckMessagesFragment"
android:menuCategory = "secondary"/>
<item android:id="@+id/helpFragment"
android:title="@string/str_help"
android:icon="@drawable/baseline_assignment_24"
android:label="HelpFragment"
android:menuCategory = "secondary"/>
</menu>
Here is the main nav graph.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_nav_graph"
app:startDestination="@id/job_navigation">
<activity
android:id="@+id/mainActivity"
android:name="com.davidozersky.posterpal.ui.activity.MainActivity"
android:label="MainActivity" />
<fragment
android:id="@+id/settingsFragment"
android:menuCategory = "secondary"
android:name="com.davidozersky.posterpal.ui.fragments.SettingsFragment"
android:label="Setting">
<action android:id="@+id/action_global_settingsFragment"/>
</fragment>
<!-- app:popUpTo="@id/jobsListFragment"-->
<!-- app:popUpToInclusive="true"-->
x
<!-- -->
<include app:graph="@navigation/sign_up_login" />
<!-- <include app:graph="@navigation/settings_graph"/>-->
<include app:graph="@navigation/job_navigation" />
<!-- <include app:graph="@navigation/drawer_navigation" />-->
<fragment
android:id="@+id/checkMessagesFragment"
android:menuCategory = "secondary"
android:name="com.davidozersky.posterpal.ui.fragments.CheckMessagesFragment"
android:label="CheckMessagesFragment" />
<fragment
android:id="@+id/helpFragment"
android:menuCategory = "secondary"
android:name="com.davidozersky.posterpal.ui.fragments.HelpFragment"
android:label="HelpFragment" />
<fragment
android:id="@+id/postJobsFragment"
android:menuCategory = "secondary"
android:name="com.davidozersky.posterpal.ui.fragments.PostJobsFragment"
android:label="PostJobsFragment" />
<fragment
android:id="@+id/registerJobOwnerFragment"
android:menuCategory = "secondary"
android:name="com.davidozersky.posterpal.ui.fragments.RegisterJobOwnerFragment"
android:label="RegisterJobOwnerFragment" />
</navigation>
This is what the backstack looks like from the settings page through the drawerlayout fragments.
I don't know what else there is to to do. There is no way to navigate to the drawerlayout items and force to add them to the backstack!
I am happy to hear advice, even if it is to simply avoid using the menu items in the drawerlayout at all!