Android : What is the purpose of null in addToBackStack(null)?

on Saturday, September 13, 2014


I am new to Andoid development and I have created a snippet for replacing fragments programetically.


I followed the guide on android developers.


I have create a method named selectFrag and fired it on button click:



public void selectFrag(View view)

{

Fragment fr;

if(view == findViewById(R.id.showsecond)) {
fr = new secondfragment();

}else {
fr = new firstfragment();
}

FragmentManager fm = getFragmentManager();

FragmentTransaction ft = fm.beginTransaction();

ft.replace(R.id.fragment_place,fr);

ft.addToBackStack(null);

ft.commit();
}


Code works perfectly and I understand everything except addToBackStack(null).


I experimented and understood that this method is for adding the fragment to the back button's stack, so that if we click back button, it do not leave the screen and show the previous work.


But, I do not understand what null shows here. I searched on web but I only knew that it is a TAG and we could use something like this.


So, my question is very simple :What is meant by null here? or What do null does?


(sorry for my bad English.)


0 comments:

Post a Comment