My Android app is using FragmentTabHost and has 4 tabs A,B,C,D. I'm in tab A with fragment A1, and I navigate to 2nd fragment A2 in tab A, then I switch to tab B, and then switch back to Tab A. Now I click back button which will call popBackStack() method, and I got crash saying that IllegalStateException Fragment A1 already added. Can you help? This is the code I used to create tabs in Main Tab Activity,
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("profile").setIndicator("Profile"),
ProfileFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("friends").setIndicator("Friends"),
FriendsFragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("notifications").setIndicator(
"Notifications"), NotificationFragment.class, null);
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabID) {
mTabHost.clearFocus();
}
});
and I used this code to handle back button press, FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack();