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();
}
問題は、毎回ダイアログが表示されることです。すでに起動している場合でも。時間を割いて助けてくれてありがとう、ゼオキラ。