-
Notifications
You must be signed in to change notification settings - Fork 204
Basic
qiibeta edited this page Oct 29, 2019
·
17 revisions
Scene is designed to replace the use of Activity and Fragment on navigation and page segmentation.
The main problems of Activity:
- The stack management of Activity is weak, Intent and LaunchMode are confusing, even if various of hacks still can't completely avoid issues like black screen
- The performance of Activity is poor, average startup time of an empty Activity is more than 60ms (on Samsung S9)
- Because the Activity is forced to support states recovery, it causes some problems:
- Transition animation has limited ability, difficult to implement complex interactive animations.
- Shared-element animation is basically unavailable, and there are some crashes unresolved in Android Framework.
- Every time starting a new Activity, onSaveInstance() of the previous Activity must be executed completely first, which will lose much performance.
- Activity relies on the Manifest file to cause injection difficulties, which also result in that Activity dynamics requires a variety of hacks
The main problems of Fragment:
- There are many crashes that the Google official can't solve for a long time. Even if you don't use Fragment, it may still trigger a crash in the OnBackPressed() of AppCompatActivity.
- The add/remove/hide/show operation is not executed immediately. With nest Fragments even if you use commitNow(), the status update of the sub Fragments cannot be guaranteed.
- Fragment has two lifecycles, View lifecycle and Fragment instance lifecycle.
- Fragment show/hide method only modify view visibility, none lifecycle method is invoked.
- The support of animation is poor, Z-axis order cannot be guaranteed when switching
- Navigation management is weak, there is no advanced stack management except for basic push and pop
- The lifecycle of Fragment in native Fragment and Support-v4 packages is not exactly the same
The main problems of Navigation Component:
- Only have one Lifecycle, Scene' view and Scene destroy together.
- NavigationScene responsible for backStack, GroupScene responsible for UI composition.
- NavigationScene and GroupScene operation will execute immediately exception for extreme cases (for example, push another Scene in its lifecycle method callback).
- Scene framework can disable state restore, then you can use a parameterized constructor Scene.
- Animation will be executed after Scene finished lifecycle, animation api can get two Scene's view.
Scene Components | |
---|---|
Scene | The Scene is the View wrapper with lifecycle management. |
NavigationScene | The NavigationScene implements navigation and backStack handling for Scene. |
GroupScene | The GroupScene can add other Scene/NavigationScene/GroupScene as child. |
- Home
- Background
- Installation
- Basic
- NavigationScene
- GroupScene
- Navigation Animation
- Dialog
- Router
- Style
- State Save
- Architecture-Patterns
- Activity Compatibility
- Migrate Guide
- Benchmark (compare to Activity/Fragment)