Lance,
Wonderful.
Thanks very much for your kind explanation.

Re,
ag

On Nov 14, 11:53 am, Lance Nanek <[email protected]> wrote:
> Is this what you are trying to do?
> final Handler mHandler = new Handler() {
>         public void handleMessage(Message msg) {
>                 Log.i(TAG, "Received message. Checking if location still 
> null.");
>
>                 if(location!=null){
>                         Log.i(TAG, "Location not null. Dismissing dialog.");
>                         dismissDialog(DIALOG1_KEY);
>                 } else {
>                         Log.i(TAG, "Location null. Sending delayed message to 
> check again
> later.");
>                         sendEmptyMessageDelayed(0, 100);
>                 }
>         }};
>
> showDialog(DIALOG1_KEY);
> mHandler.sendEmptyMessageDelayed(0, 100);
>
> No new thread needed. That said, why not just have whatever sets the
> location to not be null also trigger the dialog to be dismissed? If it
> is on another thread it can send the Location in a message and have
> the assignment and dismiss happen on the UI thread just as easily as
> the above causes the check to happen on the UI thread.
>
> Re Looper#prepare and Looper#loop, you would only need to call those
> if you created a Handler on your new thread. You are creating the
> Handler on the thread that was creating your new thread. If that
> thread is the UI thread, it doesn't need the looper calls because it
> already has a message queue running. Looper#loop doesn't cause your
> own code to loop anyway, it causes the code that gives out messages to
> handlers to loop.
>
> On Nov 14, 5:22 am, adag <[email protected]> wrote:
>
> > Hello,
>
> > Here is my code:
> > --------------------------------------
> > final Handler mHandler = new Handler(){
> >                                 public void handleMessage(Message msg) {
> >                                         if(location!=null){
> >                                                 Log.i(TAG, "got message 
> > from handler");
> >                                                 dismissDialog(DIALOG1_KEY);
> >                                                 //this.getLooper().quit();
> >                                         }
> >                                 }
> >                         };
> >                         showDialog(DIALOG1_KEY);
>
> >                         new Thread(new Runnable() {
>
> >                                 public void run() {
>
> >                                         Looper.prepare();
> >                                                                         try 
> > {
> >                                                                             
> >     Thread.sleep(100);
> >                                                                         } 
> > catch (InterruptedException e) {
> >                                                                             
> >     // TODO Auto-generated catch block
> >                                                                             
> >     e.printStackTrace();
> >                                                                         }
> >                                                                 
> > mHandler.sendEmptyMessage(0);
> >                                         Looper.loop();
> >                                 }//end of run
> >                         }).start();
> > --------------------------------
> > The problem is as follows:
> > progressBar is showing correctly. mHandler obtains the message but
> > only once(for the first time). But I need to make it in loop(as
> > Looper.loop should have worked in this case), so it calls mHandler
> > handleMessage in every loop(but its not happening in this case).
> > The outcome progressBar kept on rotating though the condition in the
> > handleMessage (if(location!=null) )is getting satisfied in the mean
> > time of the active progressbar.
> > How can I make mHandle,sendEmptyMessage to call in each loop so I can
> > check for this (if(location!=null)) condition.
>
> > Any Suggestion would be very helpful
>
> > ag
>
>

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