Android Life Cycle Summary

Source: Internet
Author: User

Open A activity's execution Flow: OnCreate () OnStart () Onresume ()

This time if you open bactivity

A:onpause () When a loses focus, a system is added to the activity that may be destroyed.

B:oncreate () OnStart () Onresume ()

If B is a not full screen (can see aactivity), Aactivity will not execute OnStop method

If B occupies full screen, then

A:onstop ()

Now we're in bactivity we can continue to let Bactivity run also can press the home button can also press the back button

If the system is running out of memory, the system will follow the thread priority to recycle the dangerous activity (see thread priority) if it has been completely reclaimed, the memory is still overflow, then the program will crash (so we write programs must pay attention to memory leaks AH memory leaks AH)

Let's press the Back button.

B:onpause () Recovery Level 1

B:onstop () Recovery Level 2

B:ondestroy () is reclaimed by the system after execution

Back to Aactivity (if a has not been recovered by the system)

A:onresume ()

If B is full-screen,

A:onstart ()

A:onresume ()

If we press the home button,

B:onpause () Recovery Level 1

B:onstop () Recovery Level 2

Back to the main interface

Summary Highlights:

dialog does not change the life cycle, indicating that dialog is the interface within the activity

Press the back key to execute destroy and home will not execute destroy

OnPause () The persistence work in the method is really foolproof, but if you do persistent work may allow the system to compare cards, in order to experience the user, so it is recommended here to develop the most important things here to persist, the rest of the onstop to persist

Android3.0 later versions of OnStop will certainly be executed before the system is recycled so it can be done to persist data persistence work. Version 3.0 OH

System Hazard Rating:

1 If an app is interacting with the user, the process in which it is located has the highest priority;
2 If an app is visible and loses focus, such as being partially obscured by a dialog box, its process has a second high priority;
3 If the app is currently invisible and is switched to the background, its process has the third highest priority;
4 If the Background app launches a service, it has a higher priority than the same priority background app;
5 Finally, if a process does not contain any apps, then the process has the lowest priority;

Remember Android's first sentence:

DVM refers to DALIVK virtual machines. Each Android application runs in its own process and has a separate instance of the Dalvik virtual machine. Each DVM is a process in Linux, so it can be thought of as the same concept.

When we run an app, the app runs on a separate thread. It has separate threads and its own independent task, which has nothing to do with other programs.

Finally, a practical example is given to illustrate the various life cycles of the activity. Suppose a program consists of 2 activity A and B, a is the start-up interface for this program. When the user starts the program, the process and the default task are created respectively, then a is pressed into the current task, followed by OnCreate, OnStart, Onresume event is presented to the user, the user chooses a feature in a to open Interface B, Interface B is pressed into the current task to cover up the A,a OnPause event execution, B's onCreate, OnStart, Onresume event execution, rendering interface B to the user, after user interface B is finished, use the back key to return to interface A, interface B is no longer visible, Interface B of the OnPause, OnStop, OnDestroy execution, a of the Onresume event is executed, rendering interface A to the user. At this time suddenly call, interface a OnPause event is executed, the telephone answering interface is presented to the user, the user after the call, and then press the home button back to the desktop, another program "Contacts", add contact information and do some other operations, the interface A is no longer visible, its The OnStop event was executed but was not destroyed. The user then clicked on our program from the menu, because a and its processes and tasks were not destroyed, A's Onrestart and OnStart events were executed, and A's Onresume event was executed, and a was presented to the user. After the user has finished using this, press the back key to return to the desktop, a onPause, OnStop is executed, then A's OnDestroy is executed, because the current task has no activity,a the importance of the process is reduced to very low, Soon the process of a is closed by the system

Android Life Cycle Summary

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.