I am trying to call onPause()
, onStop()
, onDestroy
from a specific button to exit the application (this is my assignment details).
This is the code I've written:
Button exitBtn = (Button) findViewById(R.id.exitBtn);
exitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Button Exit clicked
// going through the LifeCycle
MainActivity.super.onPause();
MainActivity.super.onStop();
MainActivity.super.onDestroy();
}
});
But when I click the button in the application it stops suddenly and displays the message: "App has stopped". It shouldn't crash it should just exit the application