android子进程发送toast

来源:互联网 发布:js监听scroll事件 编辑:程序博客网 时间:2024/06/05 06:58

okhhtp异步请求是发生在子线程的,如果用子线程来更改UI肯定是不行的,这是Google规定:更改UI必须在主线程,也就是UI线程中才可以。在子进程中显示toast,必须使用Google提供的Handler来解决这个问题。

Handler handler = new Handler(Looper.getMainLooper());                handler.post(new Runnable() {                    @Override                    public void run() {                        Toast.makeText(ReleaseNotice.this,                                "要显示的内容",Toast.LENGTH_SHORT).show();                    }                });
原创粉丝点击