When one activity starts another activity, they all undergo a life cycle conversion. When the first activity is paused and terminated (even if it is still visible and does not want to be terminated), the other activity will be created. In this case, the data shared by the activity should be stored on a CD or elsewhere. It is essential to understand that the first activity cannot be completely terminated before the second activity is created. Otherwise, the process of the second activity being started will overwrite the process of the first activity being terminated.
Especially when switching between two activities in the same process, the lifecycle callback sequence is well defined. The following operations occur when activity a starts Activity B.
1. The onpause () method of Activity A is executed;
2. oncreate (), onstart (), and onresume () of Activity B are executed sequentially (currently Activity B has the user focus );
3. Then, if activity A is no longer displayed on the screen, its onstop () method will be executed.
The foreseeable order of lifecycle callback allows you to manage switching information between two activities. For example, when the first activity ends, you must write the data to the database so that the next activity can read it. Then, you should write the data to the database during the onpause () method execution, instead of during the onstop () method execution.