Difference between finish() and System.exit(0)

Solution 1:

Actually there is no difference if you have only one activity. However, if you have several activities on the stack, then:

  • finish() - finishes the activity where it is called from and you see the previous activity.
  • System.exit(0) - restarts the app with one fewer activity on the stack. So, if you called ActivityB from ActivityA, and System.exit(0) is called in ActivityB, then the application will be killed and started immediately with only one activity ActivityA

Solution 2:

According to android Developer -

finish()

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

System.exit(0)

The VM stops further execution and program will exit.