1

Possible Duplicate:
Android: Toast in a thread

I am calling a helper class function from a worker thread, wherein I am trying to raise a toast but I am getting following exception

Android Can't create handler inside thread that has not called Looper.prepare

Can't we raise a toast from a Non UI thread ?

Community
  • 1
  • 1
Ankuj
  • 713
  • 3
  • 10
  • 27

1 Answers1

9

You can use runOnUiThread() For example

this.runOnUiThread(show_toast);

and in show_toast

private Runnable show_toast = new Runnable()
{
    public void run()
    {
        Toast.makeText(Autoamtion.this, "My Toast message", Toast.LENGTH_SHORT)
                    .show();
    }
};
Juned
  • 6,290
  • 7
  • 45
  • 93