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 <romain...@android.com> 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 <bret.fore...@gmail.com>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 android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Romain Guy > Android framework engineer > romain...@android.com > > 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 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