我正在尝试实现此功能。在菜单按钮中,有退出功能。我有大约 6 个活动,它们都有这个菜单按钮功能。我创建了一个 ExitDialog 类,然后它可以在所有活动中使用,现在的问题是我不知道该怎么做
public class ExitDialog extends Activity {
// public ExitDialog(SessionOverview sessionOverview) {
// // TODO Auto-generated constructor stub
// }
// dialog to quit application
public void dialog() {
AlertDialog.Builder builder = new Builder(null);
builder.setMessage(R.string.to_quit);
builder.setTitle(R.string.hint);
builder.setPositiveButton(R.string.ok, new okListener());
builder.setNegativeButton(R.string.cancel, new cancelListener());
builder.create().show();
}
class okListener implements android.content.DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
class cancelListener implements
android.content.DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}
}