Reputation: 2553
I am learning Android and I am facing one issue while creating a dialogue box. I want to System.exit(0) on clicking on negative button. But I don't know how to do it. Please help me. Below is my code:
new AlertDialog.Builder(this)
.setTitle("Check Below..")
.setMessage("No Internet Connection")
.setCancelable(true)
.setPositiveButton("Go Back", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("Exit", null).show();
}
Upvotes: 0
Views: 59
Reputation: 2668
If do you want to kill the activity when the negative button is clicked, you simply have to write:
ClassName.this.finish();
Upvotes: 4
Reputation: 18112
Do something like this
new AlertDialog.Builder(this)
.setTitle("Check Below..")
.setMessage("No Internet Connection")
.setCancelable(true)
.setPositiveButton("Go Back", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.exit(0);
}
}).show();
Upvotes: 1