I read this FragmenManager replace makes overlay and the solution which stated the problem was due to defining the fragment statically in the xml. I have the same problem, but I did not define my fragment statically, I use a framelayout and the fragment manager to pop in and out my DYNAMICALLY created fragments using support fragment transactions. Here is my scenario:
Activity 1 has a framelayout called "content" in its xml.
fragment X is created and replaces framelayout "content".
When a listview item in fragment X is clicked, add fragment Y to the backstack. "content", which shows fragment X, is replaced with fragment Y.
When a button in fragment Y is clicked, fragment Z is added to the backstack. "content", which shows fragment Y, is replaced with fragment Z.
Clicking a button in fragment Z pops the backstack and replaces "content" with a new instance of fragment Y.
These steps work as expected, except after, when I press back to reach fragment X, click on a listview item, and do step 3 again. Instead of fragment Z replacing fragment Y like earlier, it overlays it. Why is this happening and how do I resolve it? Thanks
Code for step 2:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack("y_screen");
ft = ft.replace(R.id.content_frame, FragmentY.newInstance(qTitle, qDetails, qObjectID));
ft.commit();
Code for step 3:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack("z_screen");
ft.replace(R.id.content_frame, FragmentZ.newInstance(questionTitle, questionDetails,
qObjectID));
ft.commit();
Code for step 4:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fm.popBackStack();
ft.replace(R.id.content_frame, FragmentY.newInstance(questionTitle, questionDetails,
qid));
ft.commit();