Activity's life cycle in exceptional situations--android developing art exploration notes

Source: Internet
Author: User

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
    1. Front desk activity--is interacting with the user, with the highest priority
    2. Visible but non-foreground activity--activity pop-up dialogs cause activity to be visible but not interactive
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.