Activity lifecycles are fairly commonplace, but without a good understanding of the invocation of the declaration cycle, we can run into a lot of problems in development. So here I make a summary of the relevant for you to refer to.

1. First of all, I will summarize the life cycle of specific activities and when they are called

OnCreate: Creates a page. Load each element on the page into memory.

OnStart: Start page. Display the page on the screen.

OnResume: Resume the page. Make the page active on the screen, for example, start animation, start tasks, etc.

OnPause: Pauses the page. Stop the page from moving on the screen.

OnStop: Stops the page. Remove the page from the screen.

OnDestroy: Destroys the page. Clear the page from memory.

OnRestart: restarts the page. Reload the page data in memory.

2. Next, we summarize the order of lifecycle callbacks in several cases

Open a page: this page onCreate → onStart → onResume

Jump from one page to another: previous page onPause → next page onCreate → onStart → onResume → previous page onStop

Return to the previous page from one page: Next page onPause → previous page onRestart → onStart → onResume → Next page onStop → onDestroy

Portrait: Whether portrait is switched to landscape or landscape is switched to portrait, the original screen is destroyed from onPause to onStop to onDestroy, and the new screen is created from onCreate to onStart to onResume.

Press HOME and return to APP: onCreate → onStart → onResume → onPause → onStop → onRestart → onStart → onResume

OnActivityResult and onRestart call sequence: Call onActivityResult first and then onRestart