What is this error in logcat?
It says "can't create handler inside thread that has not called
looper.prepare()"
...

On Jul 31, 1:59 pm, Mystique <[email protected]> wrote:
> Nice, the dialog appear but DoSometing() crash for some reason.
> At least the logic work, let me check on the DoSomething(). It was ok
> w/o running as thread.
>
> Many thanks.
>
> On Jul 31, 1:17 pm, paulb <[email protected]> wrote:
>
>
>
> > Actually, I meant to write runInUIThread instead of closeLoadingDialog
> > in the handler.post statement
>
> > On Sat, Jul 31, 2010 at 3:16 PM, paulb <[email protected]> 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 <[email protected]> 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 [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

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