Toast from a Non-UI thread [duplicate]

一个人想着一个人 提交于 2020-01-10 04:39:04

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/13267239/toast-from-a-non-ui-thread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!