现在的位置: 首页 > 综合 > 正文

java.lang.RuntimeException: Can’t create handler inside thread that has not called Looper.prepare()

2017年12月17日 ⁄ 综合 ⁄ 共 346字 ⁄ 字号 评论关闭
Looper.prepare(); 
//开头

Builder builder = new Builder(MyBurglarService.this); 
//这里我的MyBurglarService是我的一个线程

            /*在这设置builder的属性*/

AlerDialog dialog = builder.create();
//属性设置完后创建

dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 
//设置该dialog为全局性的对话框,即在任何时候都弹出的对话框

dialog.show(); 
//弹出

Looper.loop(); 
//结尾

线程开头加个Looper.prepare();

线程结束加个Looper.loop();

抱歉!评论已关闭.