Android 架构组件生命周期状态

Android Architecture Components Lifecycle state

https://developer.android.com/reference/android/arch/lifecycle/Lifecycle.State.html

STARTED Lifecycle.State STARTED For an Activity, this state is reached in two cases: after onStart call; right before onPause call.

正如上面的文档所说,我无法理解 onPause 调用之前 STARTED 状态背后的基本原理。有人可以解释一下吗?

请注意 Lifecycle.State enum 中的值不包括 PAUSED 状态。只有五个状态:CREATED, DESTROYED, INITIALIZED, RESUMED, STARTED。这些并不完全符合我们都知道和喜爱的正常 Activity 生命周期:

另请注意 Lifecycle class documentation 中的以下内容:

ON_CREATE, ON_START, ON_RESUME events in this class are dispatched after the LifecycleOwner's related method returns. ON_PAUSE, ON_STOP, ON_DESTROY events in this class are dispatched before the LifecycleOwner's related method is called

onPause()的执行是RESUMED状态的结束边界。此时,Activity 不再被认为是 RESUMED,当然也不是 DESTROYED。由于我们没有 PAUSED 状态,因此它现在必须处于 STARTED 状态。这在技术上是正确的,Activity 尚未停止但不再恢复。