You can use do this a few ways:

- Use a name for your initial back stack state and use
FragmentManager.popBackStack(String name,
FragmentManager.POP_BACK_STACK_INCLUSIVE).
- Use FragmentManager.getBackStackEntryCount()/getBackStackEntryAt().getId()
to retrieve the ID of the first entry on the back stack, and
FragmentManager.popBackStack(int id,
FragmentManager.POP_BACK_STACK_INCLUSIVE).
- FragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
is supposed to pop the entire back stack...  I think the documentation for
that is just wrong.  (Actually I guess it just doesn't cover the case where
you pass in POP_BACK_STACK_INCLUSIVE),

On Mon, Mar 28, 2011 at 11:42 AM, Josh L <[email protected]> wrote:

> All,
>
> I am rewriting an existing application to use the Fragments/Android
> Compatibility API so that we can more easily add custom Tablet layouts
> and I have come across a problem that I'm not sure how to solve. The
> application has a custom tab-like control across the bottom which
> represent different sections of the app. Touching each of these
> sections loads a fragment that shows items in that section. Touching
> one of those items (in our phone layout) loads another fragment that
> shows the detail for that item and adds the transaction to the
> backstack such that pressing back returns the user to the list of
> items in the selected section.
>
> The problem I am having is that I want the existing back stack to be
> thrown out when a user clicks a new section at the bottom of the
> screen and there doesn't seem to be any way to do that. Here is the
> flow that creates the problem:
>
> 1. User touches section, which loads a list fragment.
> 2. User touches list item, which replaces the list fragment with a
> detail fragment and adds the list fragment to the back stack.
> 3. User clicks a new section, which replaces the detail fragment with
> a new list fragment.
> 4. User presses back, which causes the original list fragment to be
> superimposed onto the new list fragment as android navigates backwards
> through the back stack.
>
> Ideally, I would like to be able to do something like
> getFragmentManager().clearBackStack() in step 3, but this
> functionality is not exposed in the API.
>
> Workarounds:
> I can manually pop back through the back stack before showing the new
> list, but that looks ugly to the user.
> I could reload the activity passing the appropriate information to the
> new instance to go to the right tab, but again, that looks ugly to the
> user.
> I could hack the source and compile a custom version of the
> compatibility library that implements a clearBackStack function, but
> that makes it more difficult to move to pure honeycomb code later and
> requires maintenance as new versions of the compatibility library are
> released.
>
> Has anyone else run into this problem and found a more elegant
> solution? I would sincerely appreciate any thoughts anyone has.
>
> Josh Lefler
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

Reply via email to