Please comment this line in your public void onBackPressed()
Method, and it should work fine.
super.onBackPressed();
Also add .create()
on your AlertDialog
before calling .show()
:
new AlertDialog.Builder(LoginActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Exit")
.setMessage("Are you want to exit from application?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// finish();
}
})
.setNegativeButton("No", null)
.create()
.show();
I hope this helps.