Welcome reprint, Reprint please indicate the source http://blog.csdn.net/l664675249/article/details/50638398
Activity's life cycle in exceptional situations
For the life cycle of activity under normal circumstances please refer to this article, this article mainly explains the activity in the abnormal situation life cycle.
Scenario 1: Resource-related system configuration changes
Resource-related system configuration changes, for example, a chestnut. The current activity in the vertical screen when suddenly turned into a horizontal screen, the system configuration has changed, the activity will be destroyed and rebuilt, its onpause, OnStop, Ondestory will be called. The system calls Onsaveinstancestate to save the current activity state because it is actually terminated in an abnormal situation. This method is not a fixed sequence relationship with OnPause prior to OnStop. When the activity is rebuilt, the system will pass the bundles saved by Onsaveinstancestate as objects to the Onrestoreinstancestate and OnCreate methods.
Note:
- Each view in the source of the view has Onsaveinstancestate and onrestoreinstancestate two methods.
- The receive location can be onrestoreinstancestate and OnCreate method, the difference is: onrestoreinstancestate if called, the parameter bundle must be a value, In OnCreate, you need to determine if the parameter is null.
- Onsaveinstancestate is only called when the activity is about to be destroyed and has the opportunity to re-display, and will not be called during the normal destruction activity life cycle, such as rotating the screen, pressing the home key, initiating a new activity, and so on.
Scenario 2: Insufficient resource memory causes low-priority activity to be killed activity priority
- Front desk activity--is interacting with the user, with the highest priority
- Visible but non-foreground activity--activity pop-up dialogs cause activity to be visible but not interactive
- Background activity--has been suspended activity, the lowest priority
The system is running out of memory, killing the activity in the order above, and storing and recovering the data through both Onsaveinstancestate and Onrestoreinstancestate methods.
Methods that do not allow activity to be recreated
There is a lot of content in the system configuration, and when a change is made, we don't want the activity to recreate the Configchanges attribute that can be assigned to activity in Androidmainfest. Like what
android:configChanges="orientation"
Configchanges properties are very numerous, refer to official documents
There are three commonly used locales, orientation and keyboardhidden.
Activity's life cycle in exceptional situations--android developing art exploration notes