一个活动有多少个状态?
应用程序基础教程中的活动生命周期部分指出,有3 状态:
一项活动本质上包含三个 状态:
(1.活动/运行2.暂停3.停止)
但是当我继续阅读实际的Activity类文档时,Activity Lifecycle 部分指出有 4 状态:
一项活动本质上有四个 状态:
(1.活动/运行2.暂停3.停止4.“丢弃”?)
两个来源(在同一网站上)都同意前3个,但第4个仅在类文档中提到并且未命名。
那么,真的有 4 个州还是只有 3 个?
如果有4个,第4个叫什么名字?
请帮助我理解这种差异。
此外,这个漂亮且内容丰富的流程图中突出显示的彩色块似乎与各州。在流程图中,您会在哪里标记 3 或 4 种状态?
The Activity lifecycle section in the Application Fundamentals tutorial states that there are 3 states:
An activity has essentially three
states:
(1. active/running 2. paused 3. stopped)
But then as I continued reading the actual Activity class documentation, the Activity Lifecycle section states that there are 4 state:
An activity has essentially four
states:
(1. active/running 2. paused 3. stopped 4. "dropped"?)
Both sources (on the same website) agree about the first 3, but the 4th one is only mentioned in the class documentation and is unnamed.
So, are there really 4 states or only 3?
If there are 4, what is the name of the 4th one?
Please help me understand this discrepancy.
Also, highlighted colored blocks in this beautiful and very informative flowchart don't seem to correspond to the states. Where, in the flowchart, would you mark the 3 or 4 states?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将其描述为三种状态。第四个“状态”是不存在的,因为 Android 可能会破坏该活动以释放 RAM。但是,如果仍然可以通过 BACK 按钮访问该 Activity,Android 将从
onSaveInstanceState()
挂起Bundle
并在重新创建该 Activity 时使用它。如果您希望将这个缓存的Bundle
视为“状态”,我不会狡辩,但这不是我通常描述它的方式。大多数情况下,该图显示了生命周期方法的顺序。正如你所说,它是一个流程图,而不是一个状态图。
我不会。但是,活动/运行状态是绿色的“活动正在运行”气泡,暂停状态是白色的“活动不再可见”气泡,停止状态介于
onStop()
和onDestroy()
。不存在的“状态”将是红色的“进程被杀死”气泡。I would describe it as three states. The fourth "state" is non-existence, in that Android may destroy the activity to free up RAM. However, if that activity is still reachable via the BACK button, Android will hang onto the
Bundle
fromonSaveInstanceState()
and use that when it recreates the activity. If you wish to consider this cachedBundle
a "state", I wouldn't quibble, but it's not the way I usually describe it.Mostly, that diagram is showing the sequence of the lifecycle methods. As you say, it is a flowchart, more so than a state diagram.
I wouldn't. However, the active/running state is the green "activity is running" bubble, the paused state is the white "The activity is no longer visible" bubble, and the stopped state would be in between
onStop()
andonDestroy()
. The non-existence "state" would be the red "Process is killed" bubble.此图描绘了 4 个状态,第 4 个状态被标记为
被摧毁
。然而,正如你所看到的,第四个“状态”没有任何结果。也就是说,与“可离开”到另一个状态的其他 3 个状态不同,此“已销毁”状态是一个死胡同。
This diagram depicts 4 states, the 4th being labeled
Destroyed
.However, as you can see, this 4th "state" leads nowhere. That is, unlike the 3 other states which are "leave-able" to another state, this "Destroyed" state is a dead end.