Daniil Andreev
Daniil Andreev

Reputation: 69

How do I go back to previous fragment programatically with navigation component in kotlin?

I need to go back to previous fragment programatically with navigation component in kotlin. How do I set on click listener on button with this functionality?

Upvotes: 2

Views: 5184

Answers (2)

ianhanniballake
ianhanniballake

Reputation: 200080

As per the Navigation and the back stack guide, you'd want to use NavController's popBackStack() method to pop the back stack and go back to the previous fragment.

Upvotes: 4

sinha-shaurya
sinha-shaurya

Reputation: 577

You can just call popBackStack() method on your NavController, on click of that button Something like:

findNavController().popBackStack()

For more check Navigation Component docs

Upvotes: 12

Related Questions