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

Reply via email to