I created an android application with a logout option in onCreateOptionsMenu
. The Logout works perfectly but when I press the back button again it takes me to the previous activity, and when it gets a null value it redirects to login screen. Now my login screen appears again and again. I want to close the app completely when I press the back button but don't know how.
Here is my code to handle the back button press in the login screen:
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("BidNEMO")
.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) {
Main.super.onBackPressed();
finish();
}
}).create().show();
}
please help guyss..