Android开发之在子线程中使用Toast

在子线程中使用Toast的时候,出现Force close。

错误提示:Can't create handler inside thread that has not called Looper.prepare()

解决方法:

1 Looper.prepare();
2 Toast.makeText(ActivityTestActivity.this, "toast", 1).show();
3 Looper.loop();

原因:

子线程只是一个普通的线程,其ThreadLoacl中没有设置过Looper,所以会抛出异常

posted @ 2015-07-10 14:37  熠然  阅读(9551)  评论(0编辑  收藏  举报