由网友(-安于此生丶ˉTaurus)分享简介:我的应用程序接收到短信时,被调用的接收器。我想用一个简单的1按钮对话框通知用户。My application has a receiver which is invoked when an SMS is received. I want to notify the user with a simple 1 butto...
我的应用程序接收到短信时,被调用的接收器。我想用一个简单的1按钮对话框通知用户。
My application has a receiver which is invoked when an SMS is received. I want to notify the user with a simple 1 button dialog box..
这是我的code:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Hello dude").setCancelable(false).setPositiveButton("Got you", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//mp.stop();
}
}).show();
但是,它抛出一个异常:
But, it is throwing an exception :
android.view.WindowManager $ BadTokenException
android.view.WindowManager$BadTokenException
请帮忙...
推荐答案
首先,你无法显示一个对话框,一个服务
或的BroadcastReceiver
。
First, you cannot display a dialog from a Service
or BroadcastReceiver
.
二,请不要打断用户。正确的方法让用户知道这样的事情发生的背景是显示一个通知
。
Second, please DO NOT INTERRUPT THE USER. The proper way to let the user know about something like this that occurred in the background is to display a Notification
.
相关推荐
最新文章