In my activity, I call:
getFragmentManager().beginTransaction().addToBackStack(null) .add(R.id.fragment_container, new UserPlaylistsFragment()) .addToBackStack(null).commit();
This snippet is correctly added to the view. The fragment contains a list. When an item is clicked, the following code will be executed:
getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, new ViewPlaylistFragment(), "ViewPlaylistFragment").addToBackStack(null).commit();
This also works. UserPlaylistsFragment is replaced by ViewPlaylistFragment. Strange thing: When you hit the back button, nothing happens. And when you double-click the application closes (no errors).
"BackStack" doesn't seem to work for me. Anyone suggest?
My layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" > </RelativeLayout> </LinearLayout>
source share