Reputation: 69
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
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
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