Android 为什么可以';t我使用服务的上下文来显示AlertDialog
为什么我不能使用服务的上下文来显示AlertDialogAndroid 为什么可以';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
我可以用吐司来做 它可能不像构造函数中那样隐式,因为它在
上下文中作为参数
// 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。如果所讨论的服务没有活动——换句话说,用户可能正在做任何事情——从服务中弹出对话框将是非常不礼貌的。在这种情况下,使用通知
可以更好地为大多数应用提供服务。