On Fri, Jan 20, 2012 at 10:41 AM, Nick Parker <[email protected]> wrote:
> I am using the Google compatibility library for Fragments.  I have a
> ListFragment that upon selection from a context menu performs a fragment
> transaction replace to display another fragment.  This operation works fine,
> however following a screen rotation the the commit operation fails giving
> the following exception:
>
> java.lang.IllegalStateException: Can not perform this action after
> onSaveInstanceState

When I have run into this error, it is because I am calling something
on a fragment that no longer exists (e.g., destroyed in a
configuration change).

> According to the documentation I should use commitAllowingStateLoss due to
> the onSaveInstanceState being called.  When I switch to the
> commitAllowingStateLoss call I get the following error:
>
> java.lang.IllegalStateException: Activity has been destroyed

Which is also what I see when I am calling something on a fragment
that no longer exists (e.g., destroyed in a configuration change).

> Note, in the ListFragment I am overriding the onAttach and storing a
> reference to the Activity which is provided following the screen rotation.

You should not need to do that, as you can call getActivity() from any Fragment.

>  From the activity I call getSupportFragmentManager in order to perform the
> FragmentTransaction.  How is the activity becoming null?

Based on your description here, it is not becoming null. You would
have a NullPointerException if it were null.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 4.0 Programming Books: http://commonsware.com/books

-- 
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