gpt4 book ai didi

android - Activity 生命周期中 onStopped() 之前的 onPause()

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:32 25 4
gpt4 key购买 nike

在 Android Activity 生命周期中,为什么 Activity 在进入 onStopped() 之前要经过 onPause()?为什么状态不能直接进入onStopped()

最佳答案

暂停和停止是相关但不同的状态。从用户的角度来看,暂停的 Activity 无法与之交互,但可能仍然可见(例如,如果它已将不同的 Activity 作为对话框调用)。已停止的 Activity 保证完全不可见(使用在另一个 Activity 甚至不同的应用程序中)。

enter image description here

当然,stopped就是paused,反之则不然。

来自official documentation .

  • If an activity in the foreground of the screen (at the top of the stack), it is active or running.
  • If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.
  • If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

Managing the Activity Lifecycle article 中给出了更详细的解释在 Android 开发者网站的培训部分。

关于android - Activity 生命周期中 onStopped() 之前的 onPause(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23771979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com