从非UI线程吐司 [英] Toast from a Non-UI thread

查看:118
本文介绍了从非UI线程吐司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  安卓:吐司在一个线程

我打电话从工作线程创建一个辅助类功能,其中我想提出一个敬酒,但我得到以下异常

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

我们不能提高从非UI线程举杯?

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

推荐答案

您可以使用 runOnUiThread()例如

this.runOnUiThread(show_toast);

show_toast

private Runnable show_toast = new Runnable()
{
    public void run()
    {
        Toast.makeText(Autoamtion.this, "My Toast message", Toast.LENGTH_SHORT)
                    .show();
    }
};

这篇关于从非UI线程吐司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆