Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么可以';t我使用服务的上下文来显示AlertDialog_Android - Fatal编程技术网

Android 为什么可以';t我使用服务的上下文来显示AlertDialog

Android 为什么可以';t我使用服务的上下文来显示AlertDialog,android,Android,为什么我不能使用服务的上下文来显示AlertDialog 我可以用吐司来做 它可能不像构造函数中那样隐式,因为它在上下文中作为参数 // creates an AlertDialog to the instance of the Context alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Alert 1"); alertDialog.setMessage("This is an aler

为什么我不能使用服务的上下文来显示AlertDialog


我可以用吐司来做

它可能不像构造函数中那样隐式,因为它在
上下文中作为参数

// creates an AlertDialog to the instance of the Context
alertDialog = new AlertDialog.Builder(this).create(); 
alertDialog.setTitle("Alert 1");
alertDialog.setMessage("This is an alert");
// display your dialog with an OK button.
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {
    return;
  } }); 

如果所讨论的服务有一个活动,那么最好在该活动中整合您的UI。如果所讨论的服务没有活动——换句话说,用户可能正在做任何事情——从服务中弹出对话框将是非常不礼貌的。在这种情况下,使用
通知
可以更好地为大多数应用提供服务。