She did not suggest you crated the Views themselves in background thread, but that your computations were done in a background thread. You need to split the creation of the Views and whatever you are doing that's taking a long time to compute. You can also stream the UI by adding Views one after the other using Handler./View.post(Runnable).
On Sat, Nov 6, 2010 at 11:24 AM, Bret Foreman <[email protected]>wrote: > What is the best way to handle the case where drawing takes a few > seconds? I need to put up some sort of progress dialog while I work on > building the screen. > > On Nov 6, 11:18 am, Romain Guy <[email protected]> wrote: > > You should NEVER create or draw Views from a background thread. The UI > > toolkit (and the framework in general) is not thread safe. > > > > On Sat, Nov 6, 2010 at 10:21 AM, Bret Foreman <[email protected] > >wrote: > > > > > > > > > It takes some time to draw my views so I want to put up a progress > > > dialog while I do it. I set up the code like this: > > > > > public class MyActivityClass { > > > > > @Override > > > protected void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView( R.layout.myView ); > > > doBuild(savedInstanceState); > > > } > > > > > protected void doBuild( Bundle savedInstanceState ){ > > > showDialog(drawingProgressDialogId); > > > ScreenBuilder builder = new ScreenBuilder(); > > > builder.execute(savedInstanceState); > > > } > > > > > private class ScreenBuilder extends AsyncTask<Bundle , Integer , > > > LinearLayout > { > > > > > @Override > > > protected LinearLayout doInBackground(Bundle... SIS) { > > > LinearLayout topLevelLayout = new > > > LinearLayout(MyActivityClass.this); > > > doDraw( SIS[0] , topLevelLayout ); // Adds a bunch > of > > > child views > > > return topLevelLayout; > > > } > > > @Override > > > protected void onPostExecute(LinearLayout > topLevelLayout) { > > > dismissDialog(drawingProgressDialogId); > > > setContentView(topLevelLayout); > > > super.onPostExecute(topLevelLayout); > > > } > > > } > > > } > > > > > This works the first time through, where savedInstanceState is null. > > > But when there is a configuration change, like rotation and > > > savedInstanceState is not null, the dismissDialog call does not work. > > > The progress dialog remains on the screen. This is true even if doDraw > > > is stubbed so that I'm not doing anything with the savedInstanceState. > > > > > Any ideas why this behavior might occur? > > > > > -- > > > 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]<android-developers%[email protected]> > <android-developers%[email protected]<android-developers%[email protected]> > > > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > Romain Guy > > Android framework engineer > > [email protected] > > > > Note: please don't send private questions to me, as I don't have time to > > provide private support. 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]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. 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

