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

后端 未结 4 1474
醉话见心
醉话见心 2020-11-28 11:46

I\'m talking about programming in android.

In early days I thought that, finish() closes current activity and go back to the previous

4条回答
  •  渐次进展
    2020-11-28 12:21

    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

提交回复
热议问题