I am making an app using sliding menu and tab in bottom...whole app is fragment based..I am facing some problem that is I am using fragment A then click on a button and go to fragment B,in Fragment B there is a button on clicking on this button the fragment A will update with new values..and so on
means switching from A->B should be occur..but backstack should also be mantain..
Here is my code for BackStack:
public static void goToFragmentWithBackStack(Fragment fragment) {
Fragment tmp = fm.findFragmentByTag(fragment.getClass().getName());
if (tmp != null && tmp.isVisible())
return;
ft = fm.beginTransaction();
ft.add(R.id.content_frame, fragment, fragment.getClass().getName());
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
currentTag = fragment.getClass().getName();
}
Here I am using only this method to go to the next fragment. And the back button is already mantained by activity's backpressed. When I use this method and again call the Fragment A(which is already in the container) it is not called...and if I use gotoFragment method it is called but old Fragment A is destroyed(blank screen will occur).Here is my gotoFragment Method:
public static void goToFragment(Fragment fragment) {
Fragment tmp = fm.findFragmentByTag(fragment.getClass().getName());
if (tmp != null && tmp.isVisible())
return;
ft = fm.beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
currentTag = fragment.getClass().getName();
Log.d("Trong", "BackPressedcurrentTag " + currentTag);
}
I have used this concept to reused the used fragment : Android - Instantiate a Fragment multiple times
But it is not helped.Let me clear my problem again:
I want to use a used fragment again and again in a container and all the fragments should be also call on back pressed
The flow should be something like this : A->B->A->B->A AND on backpressed: A<-B<-A<-B<-A (Every time A will have new values ,new data)
Please help me.Thanks in advance.
The new instances of fragment ..I have made is something like this:
public static FollowerFragment newInstance() {
return new FollowerFragment(null,null,null);
}
public static Fragment newInstance(String cat_id,String status,String id) {
return new FollowerFragment(cat_id,status,id);
}
public FollowerFragment(String cat_id,String status,String id) {
// TODO Auto-generated constructor stub
this.str_status=cat_id;
this.counter = status;
this.user_id = id;
}