更新时间:2023-01-24 13:28:48
您不能使用应用程序[或服务]上下文。如果你真的想告诉你从一个应用程序diallog,你将有一个活动范围内传递给它。您也可以存储在活动范围内,但我的做不是 的建议。活动背景下是无效的光洁度,所以你会打破你的计划。正如@LeoLink说,只是直接从你的Activity调用它。
You can't use an application [or service] context. If you really want to show you diallog from an application, you will have to pass an Activity context to it. You could also store the Activity context, but I do not recommend that. The activity context is voided on finish, so you will break your program. As @LeoLink said, just call it directly from your Activity.
编辑例如:
class MyDialog {
public Dialog show(Context context) {
Dialog d = new Dialog(context);
d.setTitle("I'm a dialog");
d.setMessage("I'm a message");
return d.show();
}
}