Could you please explain more specifically what you are doing?  How is what
you are doing different than the Layout API demo?  The Layout API demo has
different layouts for landscape and portrait, one which has two embedded
fragments, and one which only has one of those.

On Sun, Apr 3, 2011 at 6:28 PM, blake <blake.me...@gmail.com> wrote:

> I think there is another issue, related to the one discussed in this
> thread:
>
>
> http://groups.google.com/group/android-developers/browse_thread/thread/6cfac9e17dd7afe9/0ff2c762526e1f22?lnk=gst&q=fragment#
>
> My application, as is typical, does something like this:
>
>    public void onCreate(Bundle state) {
>        super.onCreate(state);
>        setContentView(R.layout.main);
>
> R.layout.main contains a Fragment.
>
> If I get my app going and get a few fragments on the back stack, and
> then switch from portrait to landscape (or vice-versa), it crashes
> with the dreaded "IllegalState... did not create a view".
>
> The reason is that when Activity.onCreate is called any attached
> fragments are in the state INITIALIZING and are moved to CREATED.
> Unless they are mFromLayout, their onCreateView is not called.  The
> most the original fragment -- the one from the layout -- has been
> replaced by one that is not from the layout.  Boom.
>
> Calling setContentView from Activity.onStart() makes the problem go
> away.  So does setting mFromLayout true, in the fragment constructor.
>
> I'm not sure I'd call this a bug but it sure is surprising.  I'm not
> sure I understand the correct way to handle it, either.  Setting
> mFromLayout requires bare-faced hackery but it sort of seems like what
> I want: I want replacements for the original, in-layout fragment to
> behave just like it did.
>
> Moving onCreate code to onStart is, maybe, ok, but it requires doing a
> lot of initialization that probably ought to be one-time, every time
> the app becomes visible.
>
> Suggestions?
>
> -blake
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to