java.lang.RuntimeException: Only one Looper may be created per thread

开发笔记:在service中弹dialog

 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()出现这个错误

最后是看这个朋友的才弄好:http://blog.csdn.net/a740169405/article/details/11720585

调用系统权限:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />

service中的代码:

    new Thread(){
        public void run() {
            Looper.prepare();
             LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View alert_view=inflater.inflate(R.layout.custom_alert_dialog,null);
                Button alert_assign= (Button) alert_view.findViewById(R.id.alert_assign);
                alert_cancel = (Button) alert_view.findViewById(R.id.alert_cancel);
                TextView alert_message = (TextView) alert_view.findViewById(R.id.alert_message);
                alert_message.setText(message);
                countTimer = new CountTimer(15000,1000);
            final AlertDialog.Builder builder = new AlertDialog.Builder( mContext);// Builder,可以通过此builder设置改变AleartDialog的默认的主题样式及属性相关信息
            builder.setView(alert_view);
            alert_assign.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    cancle();// 当取消对话框后进行操作一定的代码?取消对话框
                }
            });
            alert_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    cancle();
                }
            });
            alertDialog = builder.create();
            alertDialog.setCancelable(false);
            alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

            alertDialog.show();
            countTimer.start();
            Looper.loop();
                }
    }.start();


}
调用系统的dialog要设置:
 alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值