Exit android app on back pressed

后端 未结 12 2121
逝去的感伤
逝去的感伤 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条回答
  •  萌比男神i
    2021-01-30 11:37

    I found an interesting solution which might help.

    I implemented this in my onBackPressed()

    finishAffinity();
    finish();
    

    FinishAffinity removes the connection of the existing activity to its stack. And then finish helps you exit that activity. Which will eventually exit the application.

提交回复
热议问题