Wednesday, September 26, 2012

[android-developers] Adding fragments to backstack in different transactions

Hello,

I have a framelayout where I am adding a listfragment and adding it to backstack. If user selects an item in that list, I start a new transaction and replace the last fragment with a new one. But when I press back button, I dont see my first list fragment, rather I see the original splash screen.

Do I have to replace fragments in same transactions to be able to navigate back to last fragment?

Here is my code:

//Adding first fragment:
private void addRouteCategoryFragment(){
        FragmentManager fm       = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft=fm.beginTransaction();
        ft.add(R.id.fragment_content, new RouteCategoryFragment(),ROUTE_CATEGORY_TAG);
        ft.addToBackStack(null);
        ft.commit();
    }

//Once user selects and item in RouteCategoryFragment, I replace it with other fragment-
private void handleRuralRoutesClick(){
        FragmentManager fm       = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, new CountyListFragment(),COUNTY_TAG);
        ft.addToBackStack(null);
        ft.commit();
    }

Thanks

Apurva

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate