Andrew Seymour
Andrew Seymour

Reputation: 250

Showing Dialog in SurfaceView

My game is drawn onto a SurfaceView. I am using a Dialog as a level completion screen, but cannot get it to show (Dialog.show()).

I keep getting the following error:

01-30 16:45:34.425: E/AndroidRuntime(3415): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

I have a Game class which extends Activity and holds the SurfaceView. I think runOnUiThread() may be the solution, but after tireless searching have no idea how to implement it inside my SurfaceView.

Any help is appreciated and I will post my code if requested (just not sure which bits are actually relevant at the moment)

Upvotes: 0

Views: 3008

Answers (1)

Grambot
Grambot

Reputation: 4524

You're attempting to modify the UI thread from a worker thread which will give these errors. To prevent this try making a call to the runOnUiThread() method...

Game.this.runOnUiThread(new Runnable() {
    public void run() {
        customDialogObject.show();
    }
});

Upvotes: 1

Related Questions