我希望每个会话仅显示一次警报。 我在onCreateView中调用此方法,但只想显示一次
private void ShowDialog() {
new SweetAlertDialog(getContext())
.setTitleText("Attention!")
.setContentText("Have You Checked Followup list? Check Here !!")
.setConfirmText("Followup List")
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sweetAlertDialog) {
ShowFollowupList();
sweetAlertDialog.dismissWithAnimation();
}
})
.setCancelButton("Cancel", new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
sDialog.dismissWithAnimation();
}
})
.show();
}
答案 0 :(得分:0)
登录后,将值存储在sharedPref中:
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putBoolean(“ DialogShow”,false); editor.apply();
现在在您的onCreate中,检查此值是否为false。
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getBoolean("DialogShow", false);
if (restoredText) {
showDialog();
//Now change the value of the above sharedPref to true . and dont forget to
commit the change in shared Pref
}
从应用程序注销时,清除sharedPref中的数据。