Skip to content

Commit

Permalink
chore: add lifecycle graph to comment
Browse files Browse the repository at this point in the history
  • Loading branch information
qii committed Apr 22, 2021
1 parent a463127 commit 59a4b7f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 60 deletions.
50 changes: 25 additions & 25 deletions library/scene/src/main/java/com/bytedance/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@
* Created by JiangQi on 7/30/18.
* No back stack management
*
* onAttach
* onCreate
* onCreateView
* onViewCreated
* onActivityCreated
* onViewStateRestored (only when App restore)
* onStart
* onResume
*
* onPause
* onSaveInstanceState (only when Activity or Fragment is invisible)
* onStop
* onDestroyView
* onDestroy
* onDetach
* When entering:
*
* Initial state: NONE
* +--------------+ getView() !=null +---------------+ View attached to view tree +-------------------+ Lifecycle.Event.ON_CREATE +---------+ Lifecycle.Event.ON_START +----------+ Lifecycle.Event.ON_RESUME
* | onCreateView | ------------------> | onViewCreated | ----------------------------> | onActivityCreated | ---------------------------> | onStart | --------------------------> | onResume | ----------------------------
* +--------------+ +---------------+ +-------------------+ +---------+ +----------+
*
* When entering:
* 1.onAttach -> onCreate -> onCreateView -> onViewCreated: then set state to VIEW_CREATED
* 2.onActivityCreated: set state to ACTIVITY_CREATED, and set Lifecycle to Lifecycle.Event.ON_CREATE
* 3.onStart: set state to STARTED, and set Lifecycle to Lifecycle.Event.ON_START
* 4.onResume: set state to RESUMED, and set Lifecycle to Lifecycle.Event.ON_RESUME
*
* When exiting:
* 1.onPause: set state to STARTED, and set Lifecycle to Lifecycle.Event.ON_PAUSE
* 2.onStop: set state to ACTIVITY_CREATED, and set Lifecycle to Lifecycle.Event.ON_STOP
* 3.onDestroyView: set state to NONE, and set Lifecycle to Lifecycle.Event.ON_DESTROY
* 4.onDestroy -> onDetach
*
* Lifecycle.Event.ON_PAUSE +---------+ Lifecycle.Event.ON_STOP +--------+ Lifecycle.Event.ON_DESTROY +---------------+ getView() == null
* --------------------------> | onPause | -------------------------> | onStop | ----------------------------> | onDestroyView | --------------------
* +---------+ +--------+ +---------------+
*
*
* Saving and restoring transient UI state:
*
* onSaveInstanceState will occur before onDestroyView for applications targeting all platforms.
*
* onSaveInstanceState will occur after onStop for applications targeting platforms >= Android9/P
*
* saving:
* +---------------------+ +---------------+
* | onSaveInstanceState | --> | onDestroyView |
* +---------------------+ +---------------+
*
* restoring:
* +-------------------+ +---------------------+ +---------+
* | onActivityCreated | --> | onViewStateRestored | --> | onStart |
* +-------------------+ +---------------------+ +---------+
*
*
* common usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,30 @@
*
* When entering:
*
* 1. Parent: onAttach -> onCreate -> onCreateView -> onViewCreated
* (synchronize the state of child Scene)
* 2. Child: onAttach -> onCreate -> onCreateView -> onViewCreated
* 3. Parent: onActivityCreated
* (synchronize the state of child Scene)
* 4. Child: onActivityCreated
* 5. Parent: onStart
* (synchronize the state of child Scene)
* 6. Child: onStart
* 7. Parent: onResume
* (synchronize the state of child Scene)
* 8. Child: onResume
* +----------------------+ +--------------------+ +--------------------------+ +-------------------------+ +----------------+ +---------------+ +-----------------+ +----------------+
* | Parent onViewCreated | --> | sync_1 | --> | Parent onActivityCreated | --> | sync_2 | --> | Parent onStart | --> | sync_3 | --> | Parent onResume | --> | sync_4 | ---
* +----------------------+ +--------------------+ +--------------------------+ +-------------------------+ +----------------+ +---------------+ +-----------------+ +----------------+
* | | | |
* | sync | sync | sync | sync
* v v v v
* +--------------------+ +--------------------------+ +-------------------------+ +---------------+ +----------------+
* | Child onCreateView | --> | Child onViewCreated | | Child onActivityCreated | | Child onStart | | Child onResume |
* +--------------------+ +--------------------------+ +-------------------------+ +---------------+ +----------------+
*
*
*
* When exiting:
*
* (Force set state of Scene to State.STARTED)
* 1. Child: onPause
* 2. Parent: onPause
* (Force set state of Scene to State.ACTIVITY_CREATED)
* 3. Child: onStop
* 4. Parent: onStop
* (Force set state of Scene to State.NONE)
* 3. Child: onDestroyView -> onDestroy -> onDetach
* 4. Parent: onDestroyView -> onDestroy -> onDetach
* +---------------+ +----------------+ +--------------+ +---------------+ +---------------------+ +----------------------+
* | Child onPause | --> | sync_1 | --> | Child onStop | --> | sync_2 | --> | Child onDestroyView | --> | sync_3 | ---
* +---------------+ +----------------+ +--------------+ +---------------+ +---------------------+ +----------------------+
* | | |
* | sync | sync | sync
* v v v
* +----------------+ +---------------+ +----------------------+
* | Parent onPause | | Parent onStop | | Parent onDestroyView |
* +----------------+ +---------------+ +----------------------+
*
*
* TODO: Must support transaction, so we can add and hide without trigger onResume().
* Otherwise, ViewPager will be difficult to handle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,37 @@
* (NavigationScene cannot be inherited)
*
* When entering:
* 1.Parent: onAttach -> onCreate -> onCreateView -> onViewCreated -> onActivityCreated
* (All child Scenes start the life cycle process after NavigationAccCreate's onActivityCreated)
* (The previously pushed Scene will be cached)
* 2.Child: onAttach -> onCreate -> onCreateView -> onViewCreated -> onActivityCreated
* 3.Parent: onStart
* 4.Child: onStart
* 5.Parent: onResume
* 6.Child: onResume
*
* +-------------------------+
* | Child onStart |
* +-------------------------+
* ^
* | sync
* |
* +--------------------------+ +--------------------+ +---------------------+ +-------------------------+ +-----------------+ +----------------+
* | Parent onActivityCreated | --> | sync_1 | --> | Parent onStart | --> | sync_2 | --> | Parent onResume | --> | sync_3 | ---
* +--------------------------+ +--------------------+ +---------------------+ +-------------------------+ +-----------------+ +----------------+
* | |
* | sync | sync
* v v
* +--------------------+ +---------------------+ +-------------------------+ +----------------+
* | Child onCreateView | --> | Child onViewCreated | --> | Child onActivityCreated | | Child onResume |
* +--------------------+ +---------------------+ +-------------------------+ +----------------+
*
*
*
* When exiting:
* 1.Child: onPause
* 2.Parent: onPause
* 3.Child: onStop
* 4.Parent: onStop
* 5.Child: onDestroyView -> onDestroy -> onDetach
* 6.Parent: onDestroyView -> onDestroy -> onDetach
*
* +---------------+ +----------------+ +--------------+ +---------------+ +---------------------+ +----------------------+
* | Child onPause | --> | sync_1 | --> | Child onStop | --> | sync_2 | --> | Child onDestroyView | --> | sync_3 | ---
* +---------------+ +----------------+ +--------------+ +---------------+ +---------------------+ +----------------------+
* | | |
* | sync | sync | sync
* v v v
* +----------------+ +---------------+ +----------------------+
* | Parent onPause | | Parent onStop | | Parent onDestroyView |
* +----------------+ +---------------+ +----------------------+
*
*/
public final class NavigationScene extends Scene implements NavigationListener, SceneParent, SuppressOperationAware {
private static final String KEY_NAVIGATION_SCENE_SUPPORT_RESTORE_ARGUMENT = "bd-scene-navigation:support_restore";
Expand Down

0 comments on commit 59a4b7f

Please sign in to comment.