在子线程中使用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,所以会抛出异常

相关文章:

  • 2021-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-10-21
  • 2022-01-07
猜你喜欢
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-11-24
  • 2022-02-18
相关资源
相似解决方案