The life cycle of Android--activity (ii)

Source: Internet
Author: User

1. How the Activity Works

In our application, when there are multiple activity transitions, how they switch. In the previous article, we learned about several functions of the activity life cycle, and the execution of these functions when jumps occur in the activity.
In this article, I want to go further and explore how the activity works.
When we firstactivity jump to secondactivity, and then press the back key in Secondactivity, and return to Firstactivity, this last-in-first-out method is similar to the stack in the data structure.
Look at the corresponding document, sure enough, the activity of the internal principle is the way stack.
The following picture is how activity works:

    • The current program does not start, as shown in 1, is an empty.
    • After the program starts, the activity that is started by default will be added, if it is firstactivity, if the jump to Secondactiviy occurs in firstactivity, then secondactivity into the stack. In the secondactivity and jump to thirdactivity, and then put thirdactivity into the stack.
    • If you click Back in Thirdactivity to exit, then pop thirdactivity, return to Secondactivity, and so on.
    • Note that there may be a special case where the activity does not go back and should supposedly be stored in the stack. But our phone's memory is limited, it is likely because of the open application too much, causing the system to destroy inactive activity. For example, such as 2, the current is thirdactivity, and firstactivity and Secondactivity is in the inactive state, if at this time the memory is not enough, will release firstactivity or secondactivity memory for the program to function properly. As for how to release, but also to see the operating system scheduling mechanism.
2, the supplement of the previous article

As illustrated in the previous article, when an activity is in the process of jumping into another activity. In fact, in the official documentation, a diagram is given:

Detailed description of the activity of the life cycle, see the picture is relatively simple and clear.
Of course, you can rewrite those functions by yourself. Try it, and it will deepen the impression.

The life cycle of Android--activity (ii)

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.