Previous fragment visible below new fragment
android, android-fragments, listview
Solution
I know it's too late but this answer can help others. it's not a proper solution but it's working for me. So put `android:clickable="true"` and `android:background="?android:attr/colorBackground"` in the root view of your fragment. hope this will work.
Problem
I have a TabLayout with a ViewPager. The ViewPager have four fragments F1, F2, F3 and F4. F1 contains a FrameLayout which can have 2 fragments F11 and F12. Initially I add F11 in the FrameLayout with below code. ``` Fragment11 fragment11 = new Fragment11(); fragment11.setArguments(getActivity().getIntent().getExtras()); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, fragment11, Constants.FRAGMENT_11) .commit(); ``` F11 contains a ListView. When I click on any item/row in this ListView then F11 is replaced with F12. F12 is a detail fragment. ``` Fragment12 fragment12 = new Fragment12(); FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment12, Constants.FRAGMENT_12) .addToBackStack(null) .commit(); ``` For normal app flow it works fine. Now suppose currently I am in Fragment12 and I pressed home button. Now I open any heavy application (camera or any other app) to remove my app from memory. Now I started my app again. Now there are two Fragment11 and one Fragment12 are visible, all at the same time. When I press back Fragment12 is removed and now two Fragment11 are visible. When I click the ListView row of Fragment11 then the top Fragment11 is replaced with Fragment12, however, the bottom Fragment11 remains there. This is what I want: When the app comes to the foreground from background then Fragment12 should be visible and when I press back Fragment12 should be popped to show Fragment11. How can I do this?