W
Sent via BlackBerry by AT&T

-----Original Message-----
From: CG <[EMAIL PROTECTED]>

Date: Mon, 8 Sep 2008 10:02:58 
To: Android Developers<android-developers@googlegroups.com>
Subject: [android-developers] Re: Alert Dialog never displayed in when call in
 the run() method of  a separate process.



Thank you very much Huebi and hackbod, for first the solution and
taking the time to explain.

I succeded in doing what I want with Handler.

On Sep 8, 6:28 pm, Huebi <[EMAIL PROTECTED]> wrote:
> Hi,
>
> you can only display UI stuff from the main thread. You can use the
> Handler classes post() method to put the Dialog display in the event
> queue. Just have a look at the API docs.
>
> On 8 Sep., 18:16, CG <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > I am facing a strange issue. I suppose it is due to my bad
> > understanding of processes and compatibilities with processes.
>
> > So here is the behavior I'd like to have :
> > When I open my map, actions are done in background.
> > So I use a progress dialog. For that I need an separate thread.
> > But if an error occurs, I'd like to display a warning pop up. This
> > popup show request is done inside the run method of the separated
> > thread.
>
> > And the warning dialog is never displayed ! I don't understand why.
> > Can anyone explain me what is wrong ?
> > I join my code snippet to give a picture of what i try to do.
>
> > I also check the API demo and try to override the method
> > OnCreateDialog method but with the same result :-(
>
> > I suppose the issue is "when" I call the show().
>
> > ----------------- Code snippet
> > public class StationNearActivity extends MapActivity implements
> > OnClickListener, Runnable {
>
> >     /** Called when the activity is first created. */
> >     public void onCreate(Bundle icicle) {
>
> >         pgd = ProgressDialog.show(this, null,
> > getString(R.string.nearest_station_progress_dialog_wait));
>
> > /*------------------------
> >  I create the dialog here
> > -------------------------*/
> >         AlertDialog.Builder builder = new AlertDialog.Builder(this);
>
> > builder.setMessage(R.string.nearest_station_gm__popup_no_address_found_label);
> >         dlg = builder.create();
>
> > /*------------------------------
> > if I display it there then it works ! But it is not the correct
> > behaviour
> > dlg.show()
> > -----------------------------*/
>
> >         super.onCreate(icicle);
> >         thisInstance = this;
>
> >         mapViewFromXML.setClickable(true);
> >         mapViewFromXML.setEnabled(true);
>
> >         }
>
> >         Thread threadOfMap = new Thread(this);
> >         threadOfMap.start();
> >     }
>
> >     public void run() {
> >         Looper.prepare();
>
> >         try {
> >             Thread.sleep(200);
> >         } catch (InterruptedException e) {
> >             // TODO Auto-generated catch block
> >             e.printStackTrace();
> >         }
>
> >         // --- Fill the map
> >         try {
> >             setMapCenter();
> >             if (mapCenter == null || (mapCenter.getLatitudeE6() == 0
> > && mapCenter.getLongitudeE6() == 0)) {
>
> > /*------------------------------
> > The "progress dialog dismiss" works but the "dialog show" not !
> > -----------------------------*/
>
> >                 pgd.dismiss();
> >                 dlg.show();
> >             }
>
> >             Log.d("MAP", "add overlay");
> >            //....
> >             mapViewFromXML.postInvalidate();
>
> >         } catch (Exception e) {
> >             Log.e(Constant.LOG_NS2_MAP, e.toString(), e);
> >         } finally {
> >             pgd.dismiss();
> >         }
> >     }
>
> > }


--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to