I want to show a AlertDialog in my app (whether quit app or not) when user press Home. I read that Home can't be overrided. So, I tried to override onPause method. It works fine when I press Back Button. But, the problem is in Home Button. It shows the dialog when I press Home button, but it sends the app to background before I do any action on the dialog. Is there a way to do some work before it sends the app to background?
My work:
@Override
protected void onPause() {
super.onPause();
if (clr.equals("red")) {
AlertDialog.Builder alertD = new AlertDialog.Builder(this);
alertD.setMessage("Do you want to cancel your schedule?")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
finish();
}
});
alertD.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveTaskToBack(true);
}
});
AlertDialog alertDD = alertD.create();
alertDD.show();
}
}