Hi Mark, Thanks for the quick response, I've included my comments inline:
Nick Parker On Friday, January 20, 2012 at 9:49 AM, Mark Murphy wrote: > On Fri, Jan 20, 2012 at 10:41 AM, Nick Parker <[email protected] > (mailto:[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). > > This makes sense, I understand the issue with calling commit, I have not problem switching to commitAllowingStateLoss(). > > > 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. I was initially just calling getActivity() from the ListFragment, however that was returning null. When I captured the Activity in the onAttach method I ran into the issue during the commitAllowingStateLoss(). > > > 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. > > I was just following the stack trace and using JD-GUI to look at the code. More of the stack trace looks like this: java.lang.IllegalStateException: Activity has been destroyed at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1314) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541) at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:529) JD-GUI shows inside the enqueueAction method an IllegalStateException is thrown when the Activity is null. Do you have any suggestions to get around this. I'd really just like to be able to perform replace operations on a FragmentTransaction following screen rotations. Thanks again. > > -- > 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] > (mailto:[email protected]) > To unsubscribe from this group, send email to > [email protected] > (mailto:[email protected]) > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > > -- 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

