How do you display a Toast from a background thread on Android?

Arutha picture Arutha · Jun 28, 2010 · Viewed 101.1k times · Source

How can I display Toast messages from a thread?

Answer

Lauri Lehtinen picture Lauri Lehtinen · Jun 28, 2010

You can do it by calling an Activity's runOnUiThread method from your thread:

activity.runOnUiThread(new Runnable() {
    public void run() {
        Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show();
    }
});