Which actions does the back button/back key on Android trigger?

前端 未结 2 1925
感情败类
感情败类 2021-01-13 09:21

I am really confused. I have read that the back button

  • calls onDestroy()
  • can close up your currently-running activity
  • calls onPause()
  • <
相关标签:
2条回答
  • 2021-01-13 10:03

    Just to add, browser application overrides onBackPressed() to go back to previously opened tabs (if available) and it not, closes the application.

    0 讨论(0)
  • 2021-01-13 10:12

    I have read that the back button calls onDestroy(), can close up your currently-running activity, calls onPause()

    All three are correct.

    I found nothing in the docs.

    Quoting the Android documentation:

    When the user presses the BACK key, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored).

    To elaborate, if there is nothing else that will consume the BACK button press (e.g., an open options menu), your Activity will be called with onBackPressed(). The default implementation of this calls finish(). This will take your activity from the running to the destroyed states, calling onPause(), onStop(), and onDestroy() in sequence, as shown in the event flow diagram:

    enter image description here

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题