Explore life cycle of Activity
1. life cycle analysis in typical situations :onCreate initialization work, loading layout resources and data;onStart ac is starting but cannot interact, backstage;onresume ac is visible, Displayed at the front desk;onPause is stopping and must be executed before the new AC can be executed ;Onstop is about to stop, recycling work; Ondestory imminent destruction, recovery and release of resources;onrestart Restart
2.onStart and onresume,onPause and onStop, what are the real differences.
A :onStart and onresume are callbacks from the perspective of Activity visibility; The Activity is in the foreground at the angle of the callback.
3.in the newActivitybefore starting, the top of the stackActivityneed to firstOnPauseafter the newActivityto start. Not inOnPausein order to do the heavyweight operation because it must beOnPauseafter the execution completes the newActivitytoResume. So: we knowOnPauseand theOnStopare not able to perform time-consuming operations, especiallyOnPause, which also means that we should try toOnStopso that the newActivityshow it as soon as possible and switch to the foreground
4. life cycle analysis in exceptional situations
- ) Situation1: A change in resource-related system configuration has resulted inActivitybe killed and re-created
- Example: Current Activity is in a vertical state, and if you suddenly rotate the screen, the activity is destroyed and recreated by default due to changes in the system configuration.
- in this unexpected situation, the system calls Onsaveinstancestate to save The state of the current Activity. This method only occurs in the event of an abnormal termination, and when the new Activity is created, the system calls onrestoreinstancestate Remove the previously saved data and restore it. in terms of timing, the timing of onrestoreinstancestate calls is after OnStart .
- and the Activity , each View has S and R, all through the delegation of thought, the upper level entrusted to the lower layer, for example TextView will save its own text selection and text content.
- Insufficient resource memory results in low-priority Activity was killed .
1. A better approach is to keep the background work in Service so that the process has a certain priority.
2.Activity Points by priority: Foreground activity(interacting with user)> visible but not foreground activity (You cannot interact directly after the dialog box has been popped.) > Backstage Activity (suspended).
Android Art--a deep look at the life cycle of activity