onBackPressed:
If you define the onBackPressed () method in your activity, it means that you override the default backButton behavior, since the onBackPressed () method is called when the back button is pressed.
If you do not have the Override onBackPressed () method in your Activity, then it will call finish () for your Activity. You do not need to explicitly call the finish (). It will display the activity, which is located at the top of the activity stack, and there is an empty stack there, then you will be completely out of the application. If you have the Override onBackPressed () method, then you must explicitly call finish () to kill the activity.
The end:
If you implement the finish () method, it intended to close the current activity. If your application does not have a top backstack, you will be redirected to the Android main screen. When finish () is called, the onDestroy () method is executed for the action. This method can do things like:
- Discard any dialogs that the activity has driven.
- Close all cursors controlled by the activity.
- Close any open search dialog.
In addition, onDestroy () is not a destructor. This does not actually destroy the object. It is simply a method that is called based on a specific state. So your instance is still alive and very good * after starting and returning the onDestroy () superclass. Android supports processes in case the user wants to restart the application, this speeds up the launch phase. The process will not do anything, and if memory needs to be restored, the process will be killed
source share