I work on an app and this app has a list fragment as the starting point when you open the app. Now when I click on a listItem an update fragment opens and when you press the save button you go back to the list fragment. The problem is that when I now press the back button on my phone in order to exit the app that doesn't happen and instead I go back to the update fragment.
I would like to make it so that the update fragment doesn't get saved onto the backstack or at least I think that might do what I want. But after some research I still have a really hard time understanding the backstack and how to actually implement stuff around the backstack codewise so I hope that someone might be able to help me out. pls!
Edit1:
I added this line of code to my update button functionality.
fragmentManager?.popBackStack()
Now it looks like this:
1.) listFragment
2.) click on it -> open updateFragment -> press update button -> back to listFragment
3.) press back button of my phone and this happens so the update fragment doesn't open now but the text in the actionbar still appears as well as the back button.
Edit2:
I got rid of the line fragmentManager?.popBackStack()
and changed the Pop Behavior of the NavigationAction that leads from my update fragment to my list fragment (for clarification: my list fragment is named nav_home).
CodePudding user response:
Author here:
I changed the Pop Behavior of the NavigationAction that leads from my update fragment to my list fragment (for clarification: my list fragment is named nav_home) and now it works but I can't really explain why exactly.