Reputation: 376
I have a bottom bar with diferent tabs. When one is pressed a fragment should start. Im trying implement backStack on my project. The objective is, when i press a diferent tab, the fragment will be poped from backstack or created if does not exist.
void cretePeopleFrgament() {
boolean fragmentPopped = fragmentManager.popBackStackImmediate("Users", 0);
if (!fragmentPopped) { //fragment not in back stack, create it.
FragmentTransaction ft = fragmentManager.beginTransaction();
Fragment fraggy = new FragmentAllPeople();
ft.addToBackStack("Users");
ft.replace(R.id.conteiner, fraggy);
ft.commit();
}
setDrawerEnabled(false);
}
with this im trying to evitate conections to server
@Override
public void onStart() {
super.onStart();
Http conections(...)
}
the problem is that both one´s, popBackStackImmediate and Fragment fraggy = new FragmentAllPeople(); pass form the method on Start. How can i evitate these conections?
Upvotes: 0
Views: 102
Reputation: 12300
Switch to using a ViewPager with Fragments (and tabs). The FragmentStatePagerAdapter will do the backstack popping automatically for you then.
Upvotes: 1