I open "Activity A". "Activity A" immediately does a FragmentTransaction
like this to Open "Fragment A":
FragmentTransaction t = fm.beginTransaction();
ListFragment f = new ProfileFragment();
t.replace(R.id.main_frag, f, "act_frag");
f.setArguments(args);
t.commit();
"Fragment A" has a button on it that I would like to open a new Fragment
("Fragment B"), but keep the "Fragment A" in the backstack -- so if the user hits back, it is still around. So I do this:
FragmentTransaction t = fm.beginTransaction();
ListFragment f = new FollowFragment();
String username = tvUser.getText().toString();
Bundle args = new Bundle();
args.putString("follow", "watching");
args.putString("userprofile", username);
args.putInt("userIdprofile", userId);
f.setArguments(args);
t.replace(R.id.main_frag, f, "watching_frag");
t.addToBackStack("watching_frag");
t.commit();
I thought by adding t.addToBackStack(null);
would do the trick; and I have done it before like that. But instead, when user hit's back, it simply closes "Activity A".