我正在为 Android 制作一个应用程序,在启动屏幕上我希望它在第一次启动应用程序时显示一个 AlertDialog。这是我的代码:
SharedPreferences savedInfo = getSharedPreferences("SavedInfo", MODE_PRIVATE);
SharedPreferences.Editor infoEditor = savedInfo.edit();
boolean firstLaunch = savedInfo.getBoolean("firstLaunch", true);
final AlertDialog importDialog = new AlertDialog.Builder(SplashActivity.this).create();
if (firstLaunch == true) {
importDialog.setTitle(R.string.splash_import_title);
importDialog.setMessage(getString(R.string.splash_import_text));
importDialog.setIcon(android.R.drawable.ic_dialog_alert);
importDialog.setButton(getString(R.string.splash_import_yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//ALL FILE STUFF HERE
importDialog.dismiss();
startTimer();
}
});
importDialog.setButton2(getString(R.string.splash_import_no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
importDialog.dismiss();
startTimer();
}
});
importDialog.show();
infoEditor.putBoolean("firstLaunch", false);
} else {
startTimer();
}
问题是,它每次都向我显示对话框。即使我已经启动了它。感谢您的时间和帮助,zeokila。