Exit android app on back pressed

后端 未结 12 1955
逝去的感伤
逝去的感伤 2021-01-30 10:57

I am building an Android App. How to exit an Android App when back is pressed. Android version is 2.3.3 and above. The Android App goes to previous activity which i don\'t want.

12条回答
  •  感情败类
    2021-01-30 11:52

    In normal way you shouldn't close app - user will moves it to back by pressing home or closing your activities by pressing back.

    But you can use this tips:

    1) Close old activities after starting the new ones if they not needed in back stack:

    startActivity(newActivityIntent);
    finish();
    

    2) You can move task to back (instead of close) if you need http://developer.android.com/reference/android/app/Activity.html#moveTaskToBack(boolean)

    3) If you are really need it, you can use System.exit(0) but it's strongly not recommended and usually says that you have application's architecture problems.

提交回复
热议问题