Thank you Mike!
I changed my code like this:
public class GameView extends SurfaceView implements
SurfaceHolder.Callback {
        ...
        Dialog dialog = new Dialog(app);
        class GameThread extends Thread {
                public void run() {
                        Looper.prepare();
                        while (bRun) {
                                switch(flag){
                                case 0:
                                        break;
                                case 1:
                                        app.runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                        dialog.show();
                                                }
                                        });
                                        flag=0;
                                        break;
                                }
                        }
                }
        }
        ...
}

It works fine! Thanks All!

On Sep 22, 4:36 am, Mike <[email protected]> wrote:
> Hello,
>
> One thing that you'll need to make sure to do is run this code on the
> UI thread.  You should do this any time you are dealing with Android
> Views/Widgets.  One way you can do this by wrapping the code in case 1
> in a Runnable and then use your Activity's runOnUiThread method.
>
> - Mike
>
> On Sep 21, 11:41 am, xingye <[email protected]> wrote:
>
> > My code:
> > public class GameView extends SurfaceView implements
> > SurfaceHolder.Callback {
> >         ...
> >         Dialog dialog = new Dialog(app);
> >         class GameThread extends Thread {
> >                 public void run() {
> >                         Looper.prepare();
> >                         while (bRun) {
> >                                 switch(flag){
> >                                 case 0:
> >                                         break;
> >                                 case 1:
> >                                         dialog.show();
> >                                         flag=0;
> >                                         break;
> >                                 }
> >                         }
> >                 }
> >         }
> >         ...}
>
> > The dialog.show() was called, but noting happened.
--~--~---------~--~----~------------~-------~--~----~
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