Dnyaneshwar
Dnyaneshwar

Reputation: 160

Remove all Navigation Backstacks

I'm using new jetpack navigation library. Here I have 3 fragments A, B & C. A is my main fragment. From A fragment navigate to B fragment(A->B). From B to C(B->C). C->A then A->C->B->A->B like this. From whichever fragment I navigate if I press the system back button then I should navigate to A fragment Without having any backstacks pending.

Upvotes: 0

Views: 206

Answers (1)

apksherlock
apksherlock

Reputation: 8371

Place fragment A as a start destination and then add them all as top level destinations. For that you would need an AppBarConfiguration:

private lateinit var appBarConfiguration: AppBarConfiguration

//in onCreate or somewhere
appBarConfiguration = AppBarConfiguration(
        setOf(
            R.id.fragmentA,
            R.id.fragmentB,
            R.id.fragmentC
        )
    )
setupActionBarWithNavController(navController, appBarConfiguration)

Upvotes: 2

Related Questions