Any initialization that involves views associated with the fragment must be
done in onCreateView() (or I guess later), since that is the place where you
actually create and return your view hierarchy.

There is basically no reason to use onRestoreInstanceState(), and no need
for this with fragment.  For both activities and fragments, just restore the
data from the "savedState" variable that is passed to onCreate() etc.

On Sat, Apr 9, 2011 at 11:59 PM, Brill Pappin <[email protected]> wrote:

> I'm attempting to convert an app from a standard activity based app to a
> fragment based app and I'm a bit confused on where I should place code that
> i used to have in onCreate(Bundle).
>
> The lifecycle is pretty clear that the sequence is onCreate() ->
> onCreateView(). Additionally, it looks like onCreateView takes the place of
> onRestoreInstanceState in Activity.
>
> Whats confusing me is i used to set the layout in the activity onCreate and
> then initialize most of my internal connections to view components (fairly
> standard stuff). However now since I have not set lay layout and I do
> explicitly load the fragment layout in onCreateView, where does all that
> init code that I used to put in onCreate go (leave it in onCreate() or move
> it to onCreateView)?
> If i use onCreateView as a replacement for onRestoreInstanceState can I
> expect that my components initialized in onCreate to be available for the
> manual (read dynamic) restore?
>
> If my components are already available because they were part of the
> activity's layout, why then am i loading the fragment's layout in the
> onCreateView() ?
>
>
>
>  --
> 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




-- 
Dianne Hackborn
Android framework engineer
[email protected]

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