K
K
KnightForce2015-03-10 21:29:31
Android
KnightForce, 2015-03-10 21:29:31

Why doesn't the onBackPressed override work?

I override onBackPressed in the main Activity.
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Exit the app?")
.setMessage("Are you sure you want to exit?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton( android.R.string.yes, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
}).create().show();
}
But it exits without any dialog creation, etc.
What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivanfenenko, 2015-03-11
@ivanfenenko

@Override forgot?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question