On Fri, Aug 12, 2011 at 2:10 PM, Mark Murphy <[email protected]>wrote:

> > If so, what do I add it to to
> > keep it from getting garbage collected outside of the onCreate()?
>
> Well, in either case (<fragment> or a FragmentTransaction in
> onCreate()), you would call setRetainInstance(true) on the fragment
> itself. This tells Android to hold onto that fragment instance across
> configuration changes.


Alrite, I decided to execute the following code in my activity's onCreate():

mConfiguration = new ConfigFragment();
mConfiguration.setRetainInstance(true);
getSupportFragmentManager().beginTransaction().add(mConfiguration,
CONFIG_FRAGMENT).commit();

Now, when I rotate the screen the other fragments on my screen are having
problems similar to the post here [0]. In the portrait orientation there are
three <fragment>'s sitting next to each other in the layout (each with a
unique id like "frag_1".."frag_3"). In the landscape layout there are five
<fragment>'s (with ids like "frag_1".."frag_5"). When the system attempts to
inflate the 4th and 5th fragment it spits out the "did not create a view"
error.

If I debug into the compatibility jar it looks like the FragmentActivity is
attempting to look for existing fragments to re-use after the orientation
change. Around line 240 it attempts to find fragments by containerId and
since the configuration fragment is in the mAdded list inside the
FragmentManager with an id of zero (added by code) and the contanierId for
the 4th fragment is zero, it returns the ConfigFragment instead of calling
onCreateView() on a new instance of my 5 fragments.

Is there a way to tell the FragmentManager that a fragment I add to it
should not have a parent so that it is not a possible return value when
looking for existing fragments?

[0]
https://groups.google.com/d/topic/android-developers/6wBssALewac/discussion

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