Did the Activity get recycled or did the process get killed?

Source: Internet
Author: User

Whether it's an official Android document or a source code comment, "Jumping from activity A to activity B, a may be recycled when the system is low on memory ..." and does not specify whether a and B are part of the same app or process.

However, in the official Activity life cycle diagram, the low-priority process is said to be killed when there is not enough memory.



Then, when the memory is not enough, is the Activity is recycled, or the process was killed, or both of them appear?

The answer is that the Activity is recycled, and the process is killed, and the process is a background process.

By default, all activity within an app belongs to the same process, and the activity of different apps belongs to a different process.

However, even if Activity A and B belong to the same app, they can belong to a different process. The implementation method is to specify different processes through the Android:process property in the Androidmanifest file.

However, by setting the Android:process property in the Manifest file, we can do the same app Activity running in different processes.

<activity android:name="Com.tigerpenguin.lab.activitymemory.ActivityA"  Android:label="Multi Process"android:process=":P rocessa">                        <intent-filter>        <action android:name="Android.intent.action.MAIN" />        <category android:name="Android.intent.category.LAUNCHER" />    </intent-filter></activity><activity android:name="Com.tigerpenguin.lab.activitymemory.ActivityB"  Android:label="Activity B"android:process=":P rocessb"/>                    

When there is not enough memory, the system kills the low-priority background process, and the Activity within the process must be recycled.

The process in which the Activity is being displayed on the phone screen is the foreground process, and the rest is the background process.

"Jump from activity A to activity B ..." When B is displayed on the screen, if A and B belong to the same process, so a and B processes belong to the foreground process, so a is not killed; If A and b belong to a different process (they may belong to the same app, May also belong to a different app), when A can be killed.

Reference documents:

    • Android Activity and Low Memory

Did the Activity get recycled or did the process get killed?

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.