android 生命周期事件已创建

android lifecycle event CREATED

如果您关注 link https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State.html#CREATED 您会看到在两种情况下引发了 CREATED 事件

1) onCreate 之后(可以理解) 2) 就在 onStop 之前(等什么?)

为什么生命周期会在 onStop 之前引发 CREATED 事件?

首先,CREATED 不是一个事件,而是一个activity状态。给定的文档意味着在调用 onCreate() 之后,activity 处于 CREATED 状态(然后在调用 onResume() 之后变为 RESUMED)。当调用 activity onStop() 时,activity 再次变为 CREATED(在这种情况下 CREATED 但不是 RESUMED)。

小心,您将状态与事件混淆了!

状态(枚举值):已创建、已销毁、已初始化、已恢复、已启动

还要检查这个:https://developer.android.com/guide/components/activities/state-changes

"When a configuration change occurs, the activity is destroyed and recreated. The original activity instance will have the onPause(), onStop(), and onDestroy() callbacks triggered. A new instance of the activity will be created and have the onCreate(), onStart(), and onResume() callbacks triggered."

因此,考虑到可能的状态,CREATED 是调用 onStop 时最适合的状态