How to close application onClick of a button in Alert Box in Android?
How do I close the application in Android inside onClick()
?
My code follows something like this:
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
System.out.println("cancel clicked");
}
});
alertbox.show();
开发者_如何学PythonIf I write finish()
inside onClick
it did not help.
try this way
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
ActivityName.this.finish();
}
});
alertbox.show();
}
Try calling finish of the main activity directly. MainActivityName.this.finish();
精彩评论