如何打开对话框时,广播接收机器人? [英] How to open Dialog Box when broadcast receive in android?
问题描述
如何打开对话框
当手机状态是接受。因为每当国家
收到它导致以下错误:
android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不是一个应用程序
我该如何解决这个问题呢?
电话状态是空闲的话,我打电话对话。任何帮助将AP preciated。这是我的code。
最后一个对话框对话框=新的对话框(mcontext);
dialog.setContentView(R.layout.dialog);
dialog.setTitle(Android的自定义对话框);
最后的EditText et_remark =(EditText上)对话
.findViewById(R.id.et_remark);
按钮dialogButton =(按钮)对话框
.findViewById(R.id.btn_submit);
dialogButton
.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
dialog.dismiss();
字符串的话= et_remark.getText()
的ToString();
如果(call_duration.equals(0)){
Toast.makeText(mcontext,
小姐,
Toast.LENGTH_LONG)
。显示();
} 其他 {
如果(cType.equals(离开)){
Toast.makeText(
mcontext,
出来,
Toast.LENGTH_LONG)
。显示();
} 其他 {
Toast.makeText(mcontext,
公司,
Toast.LENGTH_LONG)
。显示();
}
}
}
});
dialog.show();
广播接收的应用程序服务(意向服务)。 href="https://developer.android.com/training/run-background-service/create-service.html" rel="nofollow">意图服务有一些限制的第一个和
然后你有一个替代方案,你可以尝试用手柄来工作,如果你的应用程序它是开放的,然后把手捕获信息,并从手柄抛出对话框。
告诉我,如果我帮你和良好的编程! How to open How can I solve this problem? Phone State is Idle then i call Dialog. Any help will be appreciated. Here is my code.
The broadcast receive is app service(intent service). The intent service have a few limitations the first one and most important is 'It can't interact directly with your user interface'. Then you have a alternative you can try to work with handle if your app it's open and then the handle captures message and throws dialog from handle.
Tell me if I helped you and good programming! 这篇关于如何打开对话框时,广播接收机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Dialog
when phone state is receive. Because whenever a State
is received it results in the following error:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
final Dialog dialog = new Dialog(mcontext);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Android Custom Dialog Box");
final EditText et_remark = (EditText) dialog
.findViewById(R.id.et_remark);
Button dialogButton = (Button) dialog
.findViewById(R.id.btn_submit);
dialogButton
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
String remark = et_remark.getText()
.toString();
if (call_duration.equals("0")) {
Toast.makeText(mcontext,
" miss",
Toast.LENGTH_LONG)
.show();
} else {
if (cType.equals("OUTGOING")) {
Toast.makeText(
mcontext,
" out ",
Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(mcontext,
" inc",
Toast.LENGTH_LONG)
.show();
}
}
}
});
dialog.show();