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

android, android-toast, multithreading

Solution

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();
    }
});

Problem

How can I display Toast messages from a thread?

Original source

Related problems