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.