Just use this code for your button:
exitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
Though it is not a good idea to use an exit button on an Android app. Let the OS decide when to kill your Activity. I should recommend, learn about the
Android Activity lifecycle first and then implement any necessary callbacks.