Android Nav component popBackStack problem

40 Views Asked by At

I have multiple backstacks 5 graphs

when i launch th app i see favorites fragment than i go to search history fragment using bottom nav then i navigate to search fragment then pop Back Stack and i see search history fragment again and this is correct behavior, but when i launch the app on android 7 and do that after pop back stack i don see search history fragment, i see favorites fragment and then if i try to click on bottom nav i get crash, why it is only on android 7 and how to solve this?

<?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_graph"
    app:startDestination="@+id/favorites_graph"
    >
    <include app:graph="@navigation/recomendations_graph"/>
    <include app:graph="@navigation/friends_graph"/>
    <include app:graph="@navigation/favorites_graph"/>
    <include app:graph="@navigation/notifications_graph"/>
    <include app:graph="@navigation/search_graph"/>
</navigation>

search graph look like:

<?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/search_graph"
    app:startDestination="@id/searchHistoryFragment">

    <fragment
        android:id="@+id/searchHistoryFragment"
        android:name="com.kamancho.melisma.searchhistory.presentation.SearchHistoryFragment"
        android:label="SearchHistoryFragment">
        <action
            android:id="@+id/action_searchHistoryFragment_to_searchFragment"
            app:destination="@id/searchFragment" />
    </fragment>
    <fragment
        android:id="@+id/searchFragment"
        android:name="com.kamancho.melisma.search.presentation.SearchFragment"
        android:label="SearchFragment">
        <action
            android:id="@+id/action_searchFragment_to_searchPlaylistDetailsFragment"
            app:destination="@id/searchPlaylistDetailsFragment"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            app:popExitAnim="@anim/nav_default_pop_exit_anim" />
    </fragment>
    <fragment
        android:id="@+id/searchPlaylistDetailsFragment"
        android:name="com.kamancho.melisma.searchplaylistdetails.presentation.SearchPlaylistDetailsFragment"
        android:label="SearchPlaylistDetailsFragment" />
</navigation>

Strat point in favorites graph favorites fragment:

<?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/favorites_graph"
    app:startDestination="@id/favoritesFragment">

    <fragment
        android:id="@+id/settingsFragment"
        android:name="com.kamancho.melisma.settings.presentation.SettingsFragment"
        android:label="SettingsFragment" />
    <fragment
        android:id="@+id/favoritesFragment"
        android:name="com.kamancho.melisma.favorites.presentation.FavoritesTracksFragment"
        android:label="FavoritesFragment">
        <action
            android:id="@+id/action_favoritesFragment_to_favoritesBottomSheetMenuFragment"
            app:destination="@id/favoritesBottomSheetMenuFragment" />
        <action
            android:id="@+id/action_favoritesFragment_to_settingsFragment"
            app:destination="@id/settingsFragment"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            app:popExitAnim="@anim/nav_default_pop_exit_anim" />
    </fragment>
    <dialog
        android:id="@+id/favoritesBottomSheetMenuFragment"
        android:name="com.kamancho.melisma.favorites.presentation.FavoritesBottomSheetMenuFragment"
        android:label="FavoritesBottomSheetMenuFragment">
        <action
            android:id="@+id/action_favoritesBottomSheetMenuFragment_to_selectPlaylistFragment"
            app:destination="@id/selectPlaylistFragment" />
    </dialog>
    <dialog
        android:id="@+id/selectPlaylistFragment"
        android:name="com.kamancho.melisma.selectplaylist.presentation.SelectPlaylistFragment"
        android:label="SelectPlaylistFragment">
        <action
            android:id="@+id/action_selectPlaylistFragment_to_createPlaylistFragment"
            app:destination="@id/createPlaylistFragment"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            app:popExitAnim="@anim/nav_default_pop_exit_anim" />
    </dialog>
    <fragment
        android:id="@+id/createPlaylistFragment"
        android:name="com.kamancho.melisma.creteplaylist.presentation.CreatePlaylistFragment"
        android:label="CreatePlaylistFragment">
        <action
            android:id="@+id/action_createPlaylistFragment_to_addToPlaylistFragment"
            app:destination="@id/addToPlaylistFragment" />
    </fragment>
    <dialog
        android:id="@+id/addToPlaylistFragment"
        android:name="com.kamancho.melisma.addtoplaylist.presentation.AddToPlaylistFragment"
        android:label="AddToPlaylistFragment" />
</navigation>
FATAL EXCEPTION: main
                 Process: com.kamancho.melisma, PID: 7582
                 java.lang.NullPointerException
                    at androidx.navigation.ui.NavigationUI.onNavDestinationSelected(NavigationUI.kt:69)
                    at androidx.navigation.ui.NavigationUI.setupWithNavController$lambda-6(NavigationUI.kt:602)
                    at androidx.navigation.ui.NavigationUI.$r8$lambda$6wzEv9QqEZKdQFS1sQQy-bdQvgE(NavigationUI.kt)
                    at androidx.navigation.ui.NavigationUI$$ExternalSyntheticLambda2.onNavigationItemSelected(D8$$SyntheticClass)
                    at com.google.android.material.navigation.NavigationBarView$1.onMenuItemSelected(NavigationBarView.java:291)
                    at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:836) 

I tried to update dependendecyes from this

implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'

to this

implementation 'androidx.navigation:navigation-fragment-ktx:2.7.2' 
implementation 'androidx.navigation:navigation-ui-ktx:2.7.2'

But nothing has changed

0

There are 0 best solutions below