If you have created a separate thread to do work in the background
independent from the UI, you wouldn't want to be doing UI in that
thread. :)  Also, you can only do UI in a thread that is running a
message loop, NOT just a random thread you have spawned (though you
should get an exception thrown back if you try to do this).

I think you probably want to send a message to the original UI thread
and have it display the dialog there.  You can just post a Runnable to
the UI thread which takes care of displaying the dialog when its run()
method is called.

On Sep 8, 9:16 am, 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