Android : Android How to properly dispose of fragments as well as from BackStack

on Friday, October 10, 2014


In my program I have this Fragment A replaced By Fragment B. Fragment A added to back stack to provide proper back navigation.


I read from another question that fragment B is still alive and just has its view destroyed and that it wont actually be disposed until the activity its attached to is destroyed.


I got this code in now which basically pops the back stack and removes the fragment.



getFragmentManager().popBackStack();
getActivity().getSupportFragmentManager().beginTransaction().remove(DateSearchFragment.this).commit();


My problem and question is how I can I add the remove transaction code if the back button on the phone is pressed? I.e. the button from my understanding just pops the back stack to go back to previous fragment?. The above code is carried out once the job of the fragment is done (i.e. user has done what they wanted to do with it).


This is the question I read from for reference http://stackoverflow.com/a/10046716/3364963


0 comments:

Post a Comment