Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to back to previous destination programatically using navigation controller in Android?

I have login process like the image below:

enter image description here

the user will be navigated from login screen (in the middle) to change password screen (in the right) using the code below:

 val changePassword = LoginUsingEmailFragmentDirections.actionToChangePasswordFragment()
Navigation.findNavController(fragmentView).navigate(changePassword)

I want if the user successfully change the password, I want to make the user back to login screen programatically.

If I use the old way navigation using a lot of activities, then I usually using finish()

I little bit confused what is the right way to achieve this. do I need to make action first in the graph and then using the similar code like above ? or is there any more convenient or better way to do this ?

like image 314
Alexa289 Avatar asked Jan 27 '23 14:01

Alexa289


1 Answers

You can navigate up to login screen on button click listener like below:

btn.setOnClickListener{
 Navigation.findNavController(fragmentView).navigateUp()
}
like image 200
Hussnain Haidar Avatar answered Jan 30 '23 01:01

Hussnain Haidar