Hi Mark, 

I am using setRetainInstance(true) with all of the Fragments.  I am actually 
new'ing up the detail fragment on the invocation of the onContextItemSelected() 
so there is no old reference hanging around.  After looking a bit further, I am 
starting to wonder if it has something to do with the context menu.  I am able 
to perform a separate Fragment Transaction replace operation during screen 
rotations triggered from the onListItemClick without issue.  Following screen 
rotation, I logged the getActivity() call in onCreateContextMenu which is still 
valid, but the onContextItemSelected shows getActivity() returning null.  Any 
thoughts as to why that might be?  Thanks. 


Nick Parker


On Friday, January 20, 2012 at 10:46 AM, Mark Murphy wrote:

> On Fri, Jan 20, 2012 at 11:39 AM, Nick Parker <[email protected] 
> (mailto:[email protected])> wrote:
> > I am not exactly sure what you are suggesting.  I do call
> > registerForContextMenu inside the onActivityCreated() method and super, but
> > nothing else.  Are you suggesting I do something there?
> > 
> 
> 
> I am suggesting that wherever you were calling getActivity(), and it
> was returning null, was too early in the fragment lifecycle. Solving
> that would eliminate your need to hold onto the Activity separately
> yourself, and it might clear up other problems that you are
> encountering.
> 
> >  The invocation of
> > the to perform the FragmentTransaction replace occurs from the
> > onContextItemSelected.
> > 
> 
> 
> Where are you getting the Fragment from that you are passing to
> replace()? If it not one that you instantiated just now, it may be
> that you are trying use a fragment that has been destroyed due to the
> configuration change.
> 
> BTW, are you using setRetainInstance(true) with your fragments? If
> not, bear in mind that the fragments are destroyed and recreated
> during the configuration change, when the activity is destroyed and
> recreated.
> 
> -- 
> 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

Reply via email to