Prompt user when Back button is pressed

前端 未结 5 1004
孤街浪徒
孤街浪徒 2021-02-13 16:01

Which is the good place to ask user, whether (s)he wants to exit the app when (s)he clicked the back button? I considered the onPause and onStop, but t

5条回答
  •  粉色の甜心
    2021-02-13 16:25

    If it's only when the user presses back (not home or whatever), use onBackPressed.

    The doc says:

    Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want.

    So if you catch the backpress and don't do anything, the activity is not quit. If you want to quit, use finish()

提交回复
热议问题