Hi Mark,

 

Thanks for the quick response. If I update the visibility of the "loading" and 
"main" views in the UI thread once my background thread is done, won't I have 
the same problem since I'll still be in onCreate() method and thus no visual 
impact can be observed until *after* onCreate() returns ? 

 

Emre
 
> Date: Mon, 10 Aug 2009 12:35:57 -0400
> From: [email protected]
> To: [email protected]
> Subject: [android-developers] Re: Calling setContentView() more than once in 
> method onCreate() ?
> 
> 
> Emre A. Yavuz wrote:
> > 
> > Hi,
> > 
> > I was wondering whether anybody has tried calling setContentView() more
> > than once in method onCreate() when creating an Activity. It seems only
> > the last view is displayed. Or am I missing something here ?
> > 
> > Say we have an Activity:
> > 
> > * public* *class* SampleActivyt *extends* Activity {
> > 
> > @Override 
> > 
> > * public* *void* onCreate(Bundle savedInstanceState) {
> > 
> > * super*.onCreate(savedInstanceState);
> > 
> > setContentView(R.layout./layout1/);
> > 
> > // DO SOMETHING HERE .... and when it is done change the view
> > 
> > setContentView(R.layout./layout2/);
> > 
> > }
> > }
> 
> setContentView() does not have visual impact until *after* onCreate()
> returns. If you call it twice, the net is that the user will only see
> the second.
> 
> Moreover, if "DO SOMETHING HERE" is long enough to warrant a loading
> screen, you *do not* want to be doing that work in onCreate(), anyway.
> Use AsyncTask or something else to put it in a background thread.
> 
> > You can think of it as you have a "loading" screen while a
> > computation is being done and once it's finished the view needs to be
> > changed.
> 
> Use a FrameLayout to put your loading screen and the main view in one
> layout. Set the main view to be android:visibility="gone" in the layout
> file. Once your background thread is done doing its work, in the UI
> thread (e.g., onPostExecute() in AsyncTask), make the loading screen be
> View.GONE and your main view to be View.VISIBLE.
> 
> -- 
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://twitter.com/commonsguy
> 
> Looking for Android opportunities? http://wiki.andmob.org/hado
> 
> > 

_________________________________________________________________
Send and receive email from all of your webmail accounts.
http://go.microsoft.com/?linkid=9671356
--~--~---------~--~----~------------~-------~--~----~
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