Actually, I meant to write runInUIThread instead of closeLoadingDialog in the handler.post statement
On Sat, Jul 31, 2010 at 3:16 PM, paulb <pbizan...@gmail.com> wrote: > Hello Mystique, > > When this code starts the thread, it then goes straight back to > execute DoSomeTask() while the thread is running, and so most of the > time the dialog will be shown after DoSomeTask. > > Maybe you meant to do something like this: > > ProgressDialog dialog; > > final Runnable runInUIThread = new Runnable() { > public void run() { > dialog.dismiss(); > } > } > > �...@override > public void onClick(View v) { > // TODO Auto-generated method stub > > dialog = new ProgressDialog(CloseVault.this); > dialog.setMessage("Please wait..."); > dialog.show(); > > Thread myTask = new Thread() { > �...@override > public void run() { > DoSomeTask(); > handler.post(closeLoadingDialog); > } > }; > myTask.start(); > } > > > You are right, though, ASyncTask is a nicer way of doing it. > > On Sat, Jul 31, 2010 at 2:52 PM, Mystique <joven.ch...@gmail.com> wrote: >> Hi, >> I'm trying to learn AsyncTask and Thread but Thread first... >> I am trying to display a Dialog before "DoSomeTask()" but seems like >> the Dialog always come after DoSomeTask(). >> Did I do something wrong here? >> >> Thanks. >> >> --- code--- >> >> @Override >> public void onClick(View v) { >> // TODO Auto-generated method stub >> >> mainProcessing(); >> DoSomeTask(); >> } >> >> private void mainProcessing() { >> Thread thread = new Thread(null, doBackgroundThreadProcessing, >> "Background"); >> thread.start(); >> } >> >> private Runnable doBackgroundThreadProcessing = new Runnable() { >> public void run() { >> backgroundThreadProcessing(); >> >> } >> }; >> >> private void backgroundThreadProcessing() { >> handler.post(doUpdateGUI); >> } >> >> private Runnable doUpdateGUI = new Runnable() { >> public void run() { >> updateGUI(); >> } >> }; >> >> private void updateGUI() { >> final ProgressDialog dialog = new ProgressDialog(CloseVault.this); >> dialog.setMessage("Please wait..."); >> dialog.show(); >> } >> >> -- >> 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 > -- 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