I have a customer code. There is only one activity for all of the fragments i.e. the single activity is managing all the fragments.
This activity contains the following code for any fragment at the method end of that fragment-
For example - fragment MoreFragment:
MoreFragment firstFragment = new MoreFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.article_fragment, firstFragment)
.addToBackStack(null).commit();
So,
1) What is the meaning of addToBackStack(null)
followed by a commit()
?
2) Why you need to pass a null parameter to addToBackStack
?
3) How to get that fragment after being added like this ?
Seems like this code is useless as I ran the code without the last line .addToBackStack(null).commit()
and it ran without any problems.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…