What is the difference between the methods? in the case of super.onBackPressed () can only be used within the onBackPressed () method right?
What is the difference between the methods? in the case of super.onBackPressed () can only be used within the onBackPressed () method right?
When you call super.onBackPressed()
always within onBackPressed()
, you are assuming the default behavior of the back
button on the device, that is, "back off" that ends the activity.
Image Source
The idea of doing override from the onBackPressed()
function is your ability to set the behavior you want when the user clicks the back
button on the device. If you call super.onBackPressed()
you are maintaining the behavior of the back
button, you can still add other behaviors like saving variables before closing the activity.
The finish()
(also) serves to terminate the activity that is running at any time, without having to use the back
button. You can even use another button in your app to end the activity.