我正在尝试在退出我的应用程序的活动时保存数据。
@Override
public void onBackPressed() {
super.onBackPressed();
if(loadInboxPreferencesCurrent()==false){
showAlertUserDialogInbox();
}
}
public void showAlertUserDialogInbox() {
AlertDialog.Builder builderMiniAlert = new AlertDialog.Builder(this);
builderMiniAlert.setMessage("Do you want to exit without saving your App. Inbox Settings..\n\nDo you want to Save now. ?")
.setCancelable(false); // disallow user to hit the 'back' button
builderMiniAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
//Save settings here
onBackPresedNSave();
}
});
builderMiniAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "To set your App. Inbox Settings later, press menu key and select Save Inbox Settings.", Toast.LENGTH_LONG).show();
arg0.dismiss();
}
});
builderMiniAlert.setTitle("Ultimate Sms Inbox Alert...");
builderMiniAlert.show();
}
现在真正的问题是在按下返回按钮后,对话框会显示一秒钟并消失,而无需用户单击是/否按钮。