What is the difference between the back button and the finish button?

I am working on detailing and I want to return to home activities, what is the difference between pressing the back button and calling the completion method regarding activity?

+11
source share
5 answers

If you do not have the Override onBackPressed() method from your Activity , then it will call finish() for your Activity . You do not need to explicitly call finish() ..

Thus, it will display the Activity , which is located at the top of the Activity Stack . And there is an empty Stack , then you will be completely out of the application.

If you have an Override onBackPressed() method, then you must explicitly call finish() to kill the activity.

+13
source

You can call finish() from your code; You cannot press the back button from the code. Typically, pressing the back button results in a finish() call. The difference is whether you want your code or user to initiate an action.

+3
source

As I got both the finish and back buttons, I destroy the action. The only difference I found is that when you click the back button, it gets called. onBackPress event

+2
source

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

+1
source

onFinish() Call this when your activity is complete and needs to be closed.

Call when your activity is completed and needs to be closed. The ActivityResult is passed back to the one who launched you through onActivityResult ().

onBackPressed() Called when activity detected by pressing the back key.

Called when an activity was detected by pressing the back key. The default implementation simply ends the current action, but you can override this to do whatever you want.

0
source

All Articles