如何来显示的backgroung正在运行的服务的警报diaolog(弹出式)? [英] How to display alert diaolog(popup) from backgroung running service?
问题描述
我有一个背景服务
这是不绑定到任何应用程序(或活动)的。它监控传入的消息,并在收到消息,我都显示一个对话框弹出。我试图定义一个方法,它是显示警告对话框,但它给例外,因为内螺纹无法创建处理程序,并没有所谓的活套。prepare()
我真的没有关于如何解决这个问题的任何想法。我已经搜查了许多后像这样在这里,但没有得到如何解决这一个。帮助高AP preciated。谢谢你。
I am having a background Service
which is not binded to any of the application(or Activity). It's monitoring incoming messages, and on receiving message, I have to show one dialog popup. I have tried defining one method which is for showing alert dialog, but it gives exception as "Can't create handler inside thread that has not called Looper.prepare()"
I really don't have any idea regarding how to solve this problem. I have searched many post like this over here but not getting how to resolve this one. Help highly appreciated. Thanks.
推荐答案
创建一个处理程序分开是这样的。
Create a Handler seperately like this.
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
//Call you method in This one...
displayDialog(); or whatever method name is
}
};
现在,您所呼叫的displayDialog()方法或什么都命名对话框。替换以下code。
Now where you are calling the displayDialog() method or what ever named dialog. replace the following code.
handler.sendEmptyMessage(0);
2日更多钞票的解决方案是:
2nd Posible Solution is :
把你的方法调用code内的以下内容:
put your method calling code inside the following:
runOnUiThread(new Runnable(){
public void run(){
//Call the method here
}
});
希望这有助于
Hope this helps
谢谢 沙阿
这篇关于如何来显示的backgroung正在运行的服务的警报diaolog(弹出式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!