-1

I am using Jetpack navigation to navigate between the fragments.Since I am using it for the first time I am unaware about how it will navigate from fragment two to fragment one on click of a button or based on some condition in the application.Please let me know if anyone knows about it

Sam
  • 571
  • 1
  • 6
  • 22

1 Answers1

0

Try these codes:

 yourButton.setOnClickListener(){
   activity?.onNavigateUp()
}

or

val activity = requireActivity()
yourButton.setOnClickListener(){
 if (activity is YourMainActivity) {
            activity.onSupportNavigateUp()
            //or
            activity.onBackPressed()
    }
}
TinaTT2
  • 366
  • 5
  • 17