Android activity details 4: more information about saving the activity status

Source: Internet
Author: User
Handle system configuration changes

Many devices can change system configurations during operation, such as screen orientation, keyboard layout, and language. When similar changes occur, the system will restart the running activity (call ondestroy (), and then call onstart (),-Oh ~, Onrestart () is not called. If your activity can handle the changes accordingly, your program will be more stable and cute.

So the best way to cope with these changes is to write the state storage/recovery methods. For example, onsaveinstancestate (), onrestoreinstancestate ()/oncreate ().

For detailed information about system configuration changes and how to handle the matrix, see the section "handle configuration changes during runtime.

Coordinate activities

When one activity starts another activity, both are in the lifecycle. If data is shared between the two activities, it is important to understand that when the second activity is created, the first activity has not been executed to onstop (). There is an intersection between the new one and the previous one.

When activitya starts activityb, it is executed in the following order:

1 activity
Onpause ().

2. The oncreate (), onstart (), and onresume () operations of Activity B are executed in sequence (actvityb has the user focus at this time ).

3. The onstop () of Activity A is executed (assuming that A is completely covered by B ).

You should manage data transmission between the two in this order. For example, if a wants to write data to the database and B wants to ensure that B can read the complete data written by a during initialization, A should write data in the onpause () method, but cannot be written in onstop.

Related Article

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.