My correct code is-

//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();
    }

On Wednesday, September 26, 2012 11:35:29 AM UTC-4, Apurva Goyal wrote:
>
> 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.add(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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to