How to show alert dialog in a running thread?

user1602798 picture user1602798 · Sep 13, 2012 · Viewed 29.5k times · Source

I'm developing an Android Game.In this game, There are tracks on which trains run. This is running thread. I want to show an alert dialog when there is a collision between. when I'm applying alert dialog showing error can't create handler inside thread that has not called looper.prepare().

Answer

Ankitkumar Makwana picture Ankitkumar Makwana · Sep 13, 2012

This will help you:

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // Your dialog code.
    }
});