Memory management method, electronic device, and computer-readable storage medium

By intercepting OomAdj calculations during interface switching and utilizing the judgment methods of ActivityTaskSupervisor and ActivityTaskManagerService, the system load problem caused by frequent interface switching is solved, achieving more efficient memory management.

CN120743148BActive Publication Date: 2026-07-10HONOR DEVICE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HONOR DEVICE CO LTD
Filing Date
2024-08-26
Publication Date
2026-07-10

Smart Images

  • Figure CN120743148B_ABST
    Figure CN120743148B_ABST
Patent Text Reader

Abstract

The application relates to the terminal field, in particular to a memory management method, an electronic device and a computer readable storage medium. In the method, when switching from a first interface to a second interface, and the first interface and the second interface are different interfaces in the same application, intercepting a calculation process in the process of stopping the first interface; intercepting the calculation process in the process of starting the second interface; and displaying the second interface after starting the second interface. Through the above method, the calculation process is intercepted in the interface switching process of the same application, thereby effectively reducing the system load.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal devices, and more particularly to a memory management method, electronic device, and computer-readable storage medium. Background Technology

[0002] Electronic devices typically have multiple applications installed, and users frequently switch between these applications. During each interface switch, the system performs a full OomAdj calculation, essentially scoring each application process. If system memory is insufficient, some application processes will be terminated based on the scoring, thus freeing up memory. This high-frequency execution of the full OomAdj calculation results in a significant system load. Summary of the Invention

[0003] This application provides a memory management method, an electronic device, and a computer-readable storage medium, which solves the problem of high system load when frequently switching interfaces in the prior art.

[0004] To achieve the above objectives, this application adopts the following technical solution:

[0005] Firstly, a memory management method is provided, including:

[0006] When the electronic device displays the first interface, it detects the user's first operation, wherein the first operation is used to switch the first interface to the second interface, and the first interface and the second interface are different interfaces in the same application.

[0007] In response to the first operation, the computing process is intercepted during the cessation of the first interface; wherein the computing process is used to obtain the adjustment score of each process in the system of the electronic device, the adjustment score representing the priority of the process in memory management;

[0008] The computation process is intercepted during the startup of the second interface;

[0009] After the second interface is launched, the second interface is displayed.

[0010] For example, such as Figure 7 In the embodiment described, when switching from interface A to interface B, interface A is the first interface and interface B is the second interface.

[0011] By using the method in this application embodiment, when the Activity before and after the interface switch belongs to the same application, the full OomAdj calculation can be intercepted, thereby effectively reducing the system load.

[0012] In one embodiment, a judgment method is added to ATMS, and code logic for calling the judgment method and intercepting or executing trimApplication based on the judgment method is added to ActivityTaskSupervisor.

[0013] In one implementation, the judgment method retrieves the previously foreground Activity, determines whether the previously foreground Activity and the currently foreground Activity belong to the same application, and returns the judgment result to ActivityTaskSupervisor. Specifically, if the previously foreground Activity and the currently foreground Activity belong to the same application, the judgment result is True; if the previously foreground Activity and the currently foreground Activity belong to different applications, the judgment result is False.

[0014] In this embodiment, it is necessary to save the Activity that entered the foreground for subsequent judgment method calls. One implementation can be to set a memory variable to record the Activity that was previously in the foreground. After each execution of the judgment method, the value of the memory variable (i.e., the Activity that was previously in the foreground) is replaced with the Activity that is currently in the foreground.

[0015] During the execution of the judgment method in ActivityTaskManagerService, it can obtain relevant information about the Activity from the WindowManager module, and it can also obtain information about the application to which the currently foreground Activity belongs. For example, it can retrieve the topActivity.app variable from the WindowManager module, which represents information about the application to which the currently foreground Activity belongs. If the key value of the topActivity.app variable is the same for two Activities, it means that the two Activities belong to the same application; if the key value of the topActivity.app variable is different for two Activities, it means that the two Activities belong to different applications.

[0016] In one interception method, if the judgment result is True, "return" is executed, exiting the ActivityIdleInternal method, i.e., skipping the trimApplication method, thus achieving interception of the trimApplication method. If the judgment result is False, ActivityTaskSupervisor calls the AMS's trimApplication method, i.e., performs a full calculation of OomAdj.

[0017] In this embodiment, memory management during Activity switching can be achieved by simply adding relevant logic code for the judgment method in ActivityTaskManagerService and relevant logic code for calling the judgment method and executing or intercepting trimApplication based on the judgment result in ActivityTaskSupervisor, thereby reducing system load. This method involves relatively low code development difficulty and is easy to implement.

[0018] In one implementation of the first aspect, the method further includes:

[0019] When the electronic device displays the second interface, a second user action is detected, wherein the second action is used to switch the second interface back to the first interface;

[0020] In response to the second operation, the computation process is intercepted during the cessation of the second interface;

[0021] The computation process is intercepted during the startup of the first interface;

[0022] After the first interface is launched, the electronic device displays the first interface.

[0023] For example, such as Figure 7 In the embodiment described above, when switching from interface B to interface A, interface A is the first interface and interface B is the second interface.

[0024] Using the method in this application embodiment, the first interface and the second interface are different interfaces of the same application. Switching from the first interface to the second interface and then back to the first interface, i.e., repeatedly switching between interfaces of the same application, can intercept the full OomAdj calculation multiple times, thereby reducing system load.

[0025] In one implementation of the first aspect, the method further includes:

[0026] When the electronic device displays the first interface, it detects a third operation by the user, wherein the third operation is used to switch the first interface to the third interface, and the first interface and the third interface are different interfaces in different applications.

[0027] In response to the third operation, the computing process is intercepted during the cessation of the first interface;

[0028] The calculation process is executed during the startup of the third interface;

[0029] After the third interface is launched, the third interface is displayed.

[0030] For example, such as Figure 7 In the embodiment described, when switching from interface A to interface D, interface A is the first interface and interface D is the third interface.

[0031] Using the method in this application embodiment, the first interface and the third interface belong to different interfaces of different applications. Switching from the first interface to the third interface is equivalent to switching between different interfaces of different applications. In this case, the method in this application can still perform full OomAdj calculation normally, so as to effectively manage system memory.

[0032] In one implementation of the first aspect, the method further includes:

[0033] When the electronic device displays the first interface and the fourth interface in a split screen, a fourth user operation is detected; wherein, the fourth operation is used to switch the first interface to the fifth interface and the fourth interface to the sixth interface;

[0034] In response to the fourth operation, the computing process is intercepted during the cessation of the first interface;

[0035] Intercept the computation process during the process of stopping the fourth interface;

[0036] The computation process is intercepted during the startup of the fifth interface;

[0037] The computation process is intercepted during the startup of the sixth interface;

[0038] After the fifth and sixth interfaces are launched, the fifth and sixth interfaces are displayed in a split-screen format, wherein the fifth interface is in the same position as the first interface on the display screen, and the sixth interface is in the same position as the fourth interface on the display screen.

[0039] For example, such as Figure 10In the embodiment described above, when the interface AB switches to the interface CD, interface A is the first interface, interface B is the fourth interface, interface C is the fifth interface, and interface D is the sixth interface.

[0040] By using the method in this application embodiment, when switching between different interfaces of the same application in a non-full-screen display situation, the corresponding full OomAdj calculation can be intercepted, thereby reducing the system load in a non-full-screen display situation.

[0041] In one embodiment, a judgment method is added to ATMS, and code logic for calling the judgment method and intercepting or executing trimApplication based on the judgment method is added to ActivityTaskSupervisor.

[0042] In one implementation, the judgment method determines whether the current display is full-screen; if it is full-screen, it retrieves the previous foreground Activity, determines whether the previous foreground Activity and the currently foreground Activity belong to the same application, and returns the judgment result to ActivityTaskSupervisor; if it is not full-screen, it retrieves the previous foreground Activities, determines whether the previous foreground Activities and the currently foreground Activity are in the same position and belong to the same application.

[0043] During the execution of the judgment method in ActivityTaskManagerService, one implementation is to retrieve the topActivity.app variable from the window management module. This variable represents the application information of the currently foreground Activity. It also retrieves the Activity.local variable from the window management module, which represents the Activity's position information on the screen.

[0044] One method for determining this is as follows: For any one of the previously foreground Activities (Activity 1) and the currently foreground Activity (Activity 2), check the `Activity.local` variable to see if Activity 1 and Activity 2 are in the same position. If Activity 1 and Activity 2 are in different positions, then retrieve another Activity 3 from the previously foreground Activities (excluding Activity 1) and check if Activity 3 is in the same position as Activity 2. If the position of each of the previously foreground Activities is different from the position of Activity 2, the result is False. If the position information of Activity 1 and Activity 2 is the same, then check the `Activity.app` variable to see if Activity 1 and Activity 2 belong to the same application. If Activity 1 and Activity 2 belong to the same application, then determine that the previously foreground Activity in region X and the currently foreground Activity belong to the same application, and the result is True. If Activity 1 and Activity 2 belong to different applications, then determine that the previously foreground Activity in region X and the currently foreground Activity belong to different applications, and the result is False. Here, region X is the display area corresponding to the position information of Activity 1 and Activity 2.

[0045] In one scenario, when switching from full-screen to non-full-screen display, or vice versa, the number of Activities that were previously in the foreground differs from the number of Activities that are currently in the foreground, and the corresponding display areas are different. In this case, ActivityTaskManagerService returns False to ActivityTaskSupervisor. If the number of Activities that were previously in the foreground is the same as the number of Activities that are currently in the foreground, then the judgment method is executed based on the number of Activities in the foreground.

[0046] In one scenario, when the display is not full-screen, if the Activity in a portion of the display area does not switch, the Stop Activity and Resume Activity methods will not be executed in that display area. Consequently, there is no need to execute the judgment method for the Activity in that display area.

[0047] In one implementation of the first aspect, the method further includes:

[0048] When the electronic device displays the fifth interface and the sixth interface in split screen, a fifth user operation is detected, wherein the fifth operation is used to switch the fifth interface to the first interface and the sixth interface to the fourth interface;

[0049] In response to the fifth operation, the computation process is intercepted during the cessation of the fifth interface;

[0050] Intercept the computation process during the cessation of the sixth interface;

[0051] The computation process is intercepted during the startup of the first interface;

[0052] The computation process is intercepted during the startup of the fourth interface;

[0053] After the first interface and the fourth interface are launched, the first interface and the fourth interface are displayed in a split screen.

[0054] For example, such as Figure 10 In the embodiment described above, when the interface CD switches to the interface AB, interface A is the first interface, interface B is the fourth interface, interface C is the fifth interface, and interface D is the sixth interface.

[0055] Using the method in this application embodiment, in the case of non-full-screen display, the first interface switches to the fifth interface and then switches back to the first interface, the fourth interface switches to the sixth interface and then switches back to the fourth interface. This is equivalent to repeatedly switching between different interfaces of the same application. In this case, the full OomAdj calculation can be intercepted multiple times, thereby reducing the system load in the case of non-full-screen display.

[0056] In one implementation of the first aspect, the method further includes:

[0057] When the electronic device displays the first interface and the fourth interface in a split-screen mode, a sixth user operation is detected; wherein, the sixth operation is used to switch the fourth interface to the seventh interface, and the fourth interface and the seventh interface are different interfaces in different applications;

[0058] In response to the sixth operation, the computation process is intercepted during the cessation of the fourth interface;

[0059] The computation process is executed during the startup of the seventh interface;

[0060] After the seventh interface is launched, the first interface and the seventh interface are displayed in a split screen, wherein the seventh interface and the fourth interface are in the same position on the display screen.

[0061] For example, such as Figure 12 In the embodiment described in (a), when the interface AB switches to the interface AE, interface A is the first interface, interface B is the fourth interface, and interface E is the seventh interface.

[0062] In this embodiment of the application, in a non-full-screen display scenario, if no interface switching occurs in a certain display area (the first interface does not switch), while an interface switching occurs in another display area (the fourth interface switches to the seventh interface), the full OomAdj calculation can still be performed normally according to the memory management method in this application, thereby effectively managing the system memory.

[0063] In one implementation of the first aspect, the method further includes:

[0064] When the electronic device displays the first interface and the fourth interface in a split-screen mode, a seventh user operation is detected; wherein, the seventh operation is used to switch the first interface to the fifth interface and the fourth interface to the eighth interface; the fourth interface and the eighth interface are different interfaces in different applications;

[0065] In response to the seventh operation, the computation process is intercepted during the cessation of the first interface;

[0066] Intercept the computation process during the process of stopping the fourth interface;

[0067] The computation process is intercepted during the startup of the sixth interface;

[0068] The computation process is executed during the startup of the eighth interface;

[0069] After the sixth and eighth interfaces are launched, the fifth and eighth interfaces are displayed in a split-screen manner, wherein the fifth interface and the first interface are in the same position on the display screen, and the fourth interface and the eighth interface are in the same position on the display screen.

[0070] For example, such as Figure 14 In the embodiment described above, when the interface AB switches to the interface CE, interface A is the first interface, interface B is the fourth interface, interface C is the fifth interface, and interface E is the eighth interface.

[0071] In this embodiment, the first interface switches to the fifth interface, and the fourth interface switches to the eighth interface. In one display area, the Activity that was previously in the foreground and the Activity that is currently in the foreground belong to the same application, while in another display area, the Activity that was previously in the foreground and the Activity that is currently in the foreground belong to different applications. In this case, according to the method of this embodiment, the full OomAdj calculation during the switching process of the same application interface in a certain display area can be intercepted, while the full OomAdj calculation during the switching process of different application interfaces in a certain display area is still performed. This not only effectively manages system memory but also reduces the system load of split-screen display.

[0072] In one implementation of the first aspect, the method further includes:

[0073] When the electronic device displays the first interface and the fourth interface in a split-screen mode, the user's eighth operation is detected; wherein, the eighth operation is used to switch the split-screen display to a full-screen display.

[0074] In response to the eighth operation, the computation process is executed during the cessation of the fourth interface;

[0075] After the fourth interface is stopped, the first interface is displayed in full screen.

[0076] For example, such as Figure 15 In the embodiment described above, when the interface CE switches to the interface C, the interface C is the first interface and the interface E is the fourth interface.

[0077] In this embodiment of the application, when switching from non-full-screen display to full-screen display, the method according to this embodiment of the application still performs the full OomAdj calculation during the interface switching process, thereby achieving effective management of system memory.

[0078] In one implementation of the first aspect, the method further includes:

[0079] When the electronic device displays the first interface, it detects the user's ninth operation; wherein the ninth operation is used to switch the full-screen display to a split-screen display;

[0080] In response to the ninth operation, the computation process is executed during the startup of the ninth interface;

[0081] After the ninth interface is launched, the first interface and the ninth interface are displayed in a split screen.

[0082] For example, such as Figure 15 In the embodiment described above, when interface C switches to interface AC, interface C is the first interface and interface A is the ninth interface.

[0083] In this embodiment of the application, when switching from full-screen display to non-full-screen display, the method according to this embodiment of the application still performs the full OomAdj calculation during the interface switching process, thereby achieving effective management of system memory.

[0084] In a second aspect, an electronic device is provided, including a processor for running a computer program stored in a memory to implement the method of any one of the first aspects of this application.

[0085] Thirdly, a chip system is provided, including a processor coupled to a memory, wherein the processor executes a computer program stored in the memory to implement the method of any one of the first aspects of this application.

[0086] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when executed by one or more processors, implements the method of any one of the first aspects of this application.

[0087] Fifthly, embodiments of this application provide a computer program product that, when run on a device, causes the device to perform any of the methods described in the first aspect above.

[0088] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0089] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0090] Figure 2 A schematic block diagram of the software architecture of the electronic device provided in the embodiments of this application;

[0091] Figure 3 This is a schematic diagram of the interaction process for triggering the calculation of OomAdj provided in an embodiment of this application;

[0092] Figure 4 A schematic diagram of the interface of a chat application provided in an embodiment of this application;

[0093] Figure 5 A schematic diagram of the interface of the reading application provided in the embodiments of this application;

[0094] Figure 6 A schematic diagram of the interaction flow of the memory management method provided in the embodiments of this application;

[0095] Figure 7 This is a schematic diagram illustrating an Activity switching scenario provided in an embodiment of this application.

[0096] Figure 8 This is a schematic diagram of the judgment process provided in the embodiments of this application;

[0097] Figure 9 A schematic diagram of the interaction flow of a memory management method provided in another embodiment of this application;

[0098] Figure 10 A schematic diagram illustrating the Activity switching scenario in a split-screen configuration provided in this application embodiment;

[0099] Figure 11 This is a schematic diagram of a judgment process provided for another embodiment of this application;

[0100] Figure 12 A schematic diagram illustrating the Activity switching scenario in a split-screen configuration, as provided in another embodiment of this application;

[0101] Figure 13 This is a schematic diagram of a judgment process provided for another embodiment of this application;

[0102] Figure 14 This is a schematic diagram illustrating the Activity switching scenario in a split-screen configuration provided in an embodiment of this application.

[0103] Figure 15 This is a schematic diagram illustrating the Activity switching scenario in a multi-window display situation provided in the embodiments of this application. Detailed Implementation

[0104] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limiting purposes, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details.

[0105] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0106] It should also be understood that in the embodiments of this application, "one or more" refers to one, two, or more; "and / or" describes the relationship between the associated objects, indicating that three relationships can exist; for example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following associated objects have an "or" relationship.

[0107] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," "fourth," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0108] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0109] The information transmission method provided in this application can be applied to electronic devices with screens and camera functions. Electronic devices include terminal devices, which can also be called terminals, user equipment (UE), mobile stations (MS), mobile terminals (MT), etc. Terminal devices can be mobile phones, smart TVs, wearable devices, tablets, smart screens, computers with wireless transceiver capabilities, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, and so on. The embodiments of this application do not limit the specific technologies or device forms used in the electronic devices.

[0110] See Figure 1This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a touch sensor 180K, an ambient light sensor 180L, etc.

[0111] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0112] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0113] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.

[0114] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0115] External memory 120 generally refers to external storage. In the embodiments of this application, external storage refers to storage other than the memory of electronic devices and the cache of processors. This storage is generally non-volatile memory.

[0116] Internal memory 121, also known as "RAM," can be used to store executable program code for a computer, including instructions. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a given function (such as sound playback, image playback, etc.).

[0117] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a minimized display, a microLED, a micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1. In some embodiments, electronic device 100 displays a user interface through the displays 194.

[0118] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0119] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.

[0120] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.

[0121] Electronic device 100 also includes various sensors that can convert different physical signals into electrical signals. For example, pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. Gyroscope sensor 180B can be used to determine the motion posture of electronic device 100. Barometric pressure sensor 180C is used to measure air pressure. Magnetic sensor 180D includes a Hall sensor. Accelerometer sensor 180E can detect the magnitude of acceleration of electronic device 100 in various directions (generally three axes). Distance sensor 180F is used to measure distance. Electronic device 100 can measure distance using infrared or laser. Proximity sensor 180G may include, for example, a light-emitting diode (LED) and a photodetector, such as a photodiode. Ambient light sensor 180L is used to sense ambient light brightness. Electronic device 100 can adaptively adjust the brightness of display screen 194 according to the sensed ambient light brightness. Fingerprint sensor 180H is used to collect fingerprints. Electronic device 100 can use the collected fingerprint characteristics to achieve fingerprint unlocking, access application lock, fingerprint photography, fingerprint answering of calls, etc. Temperature sensor 180J is used to detect temperature. In some embodiments, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. The bone conduction sensor 180M can acquire vibration signals.

[0122] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.

[0123] For example, in this embodiment of the application, the touch sensor 180K can detect the user's click operation on the application icon, and pass the detected click operation to the application processor to determine that the click operation is used to start or run the application, and then execute the application's running operation.

[0124] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0125] Electronic device 100 can implement audio functions, such as music playback and recording, through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.

[0126] The above is a detailed description of the embodiments of this application using electronic device 100 as an example. It should be understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on electronic device 100. Electronic device 100 may have more or fewer components than shown in the figures, may combine two or more components, or may have different component configurations. The various components shown in the figures can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.

[0127] In addition, an operating system runs on top of the aforementioned components. The operating system of the electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses the layered architecture Android system as an example to illustrate the software structure of the electronic device 100.

[0128] The software system of electronic devices can adopt a layered architecture, event-driven architecture, microkernel architecture, microserver architecture, or cloud architecture. The following provides an example of the software architecture of an electronic device.

[0129] See Figure 2This is a schematic block diagram of the software architecture of the electronic device provided in the embodiments of this application. Figure 2 As shown, the software architecture of an electronic device can include an application layer and a system layer.

[0130] The application layer can include multiple applications, each corresponding to one Activity. For example... Figure 2 As shown, the application layer includes Application 1 and Application 2, each corresponding to an Activity. The Activity for Application 1 is used to open the interface of Application 1, and the Activity for Application 2 is used to open the interface of Application 2. For example, in a camera application, the Activity for the camera application is used to open the camera application's interface and display the image in the camera viewfinder.

[0131] An Activity is a crucial component of an Android application and one of the primary ways users interact with the application. In Android applications, different Activities can be launched to provide different user interfaces and interactive experiences when users interact with the application.

[0132] The lifecycle of an Activity can include stages such as Created, Started, Resumed, Paused, Stopped, and Destroyed. In the Android system, the Activity stack is a way to manage Activities; an Activity's state determines its position in the stack. The foreground Activity is at the top of the stack. When a foreground Activity is destroyed due to an exception or other reason, the Activity at the second level of the stack will be activated and moved to the top. When a new Activity is launched and pushed onto the stack, the Activity at the top is pushed onto the second level of the stack. Changes in an Activity's position in the stack reflect its transitions between different states. Except for the topmost Activity (i.e., the active one), other Activities may be reclaimed when system memory is insufficient. The closer an Activity instance is to the bottom of the stack, the greater the likelihood that it will be reclaimed by the system.

[0133] Understandably, as the application interface switches, the state of the Activity corresponding to the switched application interface also changes. For example, if application interface 1 is in the foreground, then the Activity of application interface 1 is in the active state. When the user closes application interface 1 and opens application interface 2, application interface 2 switches to the foreground, and the Activity of application interface 2 becomes active, while the Activity of application interface 1 changes from active to destroyed.

[0134] The system layer includes multiple system components. For example... Figure 2 As shown, the system side may include the application process component (ActivityThread), the activity client control component (ActivityClientController), the activity task stack management component (ActivityTaskSupervisor, ATS), the activity stack management service component (ActivityTaskManagerService, ATMS), the animation transition component (Transition), the activity management service component (ActivityManagerService, AMS), and the memory overflow adjustment component (OomAdjuster).

[0135] The application process component (ActivityThread) is used to start Activities and handle their lifecycle. Specifically, ActivityThread is responsible for detecting and executing the lifecycle methods of each Activity, such as onCreate(), onStart(), onPause(), onStop(), and onResume(), and controlling the creation, starting, stopping, and destruction of Activities based on their lifecycle states.

[0136] The ActivityClientController component controls the ActivityClient, handling window management and application attachment operations related to Activities. The ActivityClient is the client-side component in the Android system that represents an Activity within an application; it's one of the interfaces between the Android application and the system. In Android development, the Activity is the primary interface for user interaction, while the ActivityClient represents this interface at the system level, allowing the system to manage and control the state and behavior of the Activity.

[0137] The ActivityTaskSupervisor component is used to manage the lifecycle and task stack of an Activity.

[0138] The Transition component is used for transition animations in Activities and scene animations. It allows you to smoothly transition from one screen to another or from one state to another by defining animation effects.

[0139] The ActivityManagerService (AMS) component is responsible for managing Activities, including the application lifecycle, such as launching the application, switching applications, and managing the task stack.

[0140] The OomAdjuster component dynamically adjusts the priority of each process based on the system's memory usage to ensure reasonable allocation and efficient utilization of system resources. Specifically, OomAdjuster performs a full OomAdj calculation based on the foreground / background state of application processes and the activity state of application components (such as Activities), essentially scoring each application process (adjusting the score oom_adj). If system memory is insufficient, it will terminate some application processes based on the adjusted score oom_adj, thereby freeing up memory.

[0141] It should be understood that the software architecture illustrated in the embodiments of this application does not constitute a specific limitation on the electronic device 100. The software architecture of the electronic device 100 may have more or fewer components / modules / architectural layers than shown in the figures. Figure 2 The various components shown can be implemented in a composite module that includes one or more components. Additionally, Figure 2 The names of the components shown are for ease of description and do not constitute a specific limitation on the components.

[0142] like Figure 2 The memory overflow adjustment component (OomAdjuster) described herein has its OomAdj calculation triggered based on changes in the state of the application's Activity.

[0143] For example, when switching from application interface 1 to application interface 2, the foreground activity changes from Activity A in application interface 1 to Activity B in application interface 2. The switching process from Activity A to Activity B includes stopping Activity A (stop A) and starting (or activating) Activity B (resume B). After the switch, Activity A enters the Stopped stage, meaning it is no longer in the foreground, invisible, and cannot be interacted with by the user; while Activity B enters the Resume stage, meaning it appears in the foreground, is visible, and can be interacted with by the user.

[0144] See Figure 3 This is a schematic diagram of the interactive process for triggering the calculation of OomAdj provided in the embodiments of this application.

[0145] like Figure 3 As shown in (a), the process of stopping an Activity may include the following steps:

[0146] S301, When an Activity is stopped, the Transition component executes the OnStop() method.

[0147] S302, during the execution of the OnStop() method, Transition calls the ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method in ActivityTaskSupervisor.

[0148] In the Android system, when an Activity is marked as stopped, it is no longer visible, but the system can still retain its state and resources so that it can be quickly resumed when needed. In some cases, such as when system memory is low, memory needs to be reclaimed for other applications. In this situation, the Transition calls the ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method in ActivityTaskSupervisor.

[0149] The ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method is used to retrieve a list of all stopped and finished Activities and clean them up.

[0150] S303, in the ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method, ActivityTaskSupervisor executes the ScheduleIdle method.

[0151] The ScheduleIdle method is a crucial mechanism in the Android system for managing the lifecycle of Activities. It ensures efficient resource reclamation and utilization under resource constraints, while maintaining the responsiveness and smoothness of the user interface. Specifically, ScheduleIdle is invoked during Activity switching to manage Activities that are paused or stopped, ensuring that these Activities are correctly destroyed or resumed at the appropriate time.

[0152] S304 triggers the IDLE_NOW_MSG message.

[0153] The IDLE_NOW_MSG message is triggered by events such as Activity switching and changes in Activity focus. Specifically, the IDLE_NOW_MSG message is generated when an Activity switches or its focus changes.

[0154] The IDLE_NOW_MSG message is used to trigger the memory reclamation process. Specifically, when an Activity is in an idle state, the system will send an IDLE_NOW_MSG message to trigger the ActivityIdleInternal method, thereby performing resource reclamation or optimization operations.

[0155] S305, after ActivityTaskSupervisor triggers the IDLE_NOW_MSG message, ActivityTaskSupervisor executes the ActivityIdleInternal method.

[0156] The `ActivityIdleInternal` method handles the logic related to Activity switching. Specifically, it modifies the state information of Activities in the system and adds them to different state lists. This design helps optimize the use of system resources, ensuring a fast system response and a smooth user experience when the user interacts with the interface.

[0157] S306, in the ActivityIdleInternal method, ActivityTaskSupervisor calls the AMS trimApplication method.

[0158] AMS performs memory reclamation operations by executing the trimApplication method.

[0159] S307, in the trimApplication method, AMS calls the OomAdj method in OomAdjuster to perform a full calculation of OomAdj.

[0160] like Figure 3 As shown in (b), the process of starting an Activity may include the following steps:

[0161] S308 When the system receives an Activity resume message, ActivityThread executes the OnResume() method.

[0162] S309, In ​​the OnResume() method, ActivityThread generates the resume message for the Activity that is about to be launched.

[0163] S310, ActivityThread puts the resume message into the queue.

[0164] The S310 queue can be a first-in, first-out (FIFO) stack, meaning messages that are added first are read first, and messages added later are read last. In other words, each resume message corresponds to an Activity launch task, and the launch tasks of each Activity are executed sequentially according to the queue order.

[0165] S311 processes the resume message of the Activity to be launched that is in the queue.

[0166] The process of processing each resume message in the queue may include S312-S315.

[0167] S312, ActivityThread calls the ActivityIdle method in ActivityTaskSupervisor through ActivityClientController.

[0168] The ActivityIdle method is used to handle the idle state associated with an Activity, ensuring that necessary operations can be performed efficiently and correctly when the Activity resumes its active state.

[0169] S313, In the ActivityIdle method, ActivityTaskSupervisor executes the ActivityIdleInternal method.

[0170] The ActivityIdleInternal method is an internal method of ActivityIdle. When a new Activity is launched and displayed on the screen, the system notifies AMS by calling the ActivityIdleInternal method to manage the Activity's lifecycle and system resource allocation.

[0171] S314, in the ActivityIdleInternal method, ActivityTaskSupervisor calls the AMS trimApplication method.

[0172] S315, AMS performs memory reclamation operations by executing the trimApplication method.

[0173] In the trimApplication method, AMS calls the OomAdj method in OomAdjuster to perform a full calculation of OomAdj.

[0174] Steps S313-S315 are the same as steps S305-S307, and can be found in the description of the embodiments in S305-S307.

[0175] from Figure 3 As can be seen, during a single screen transition, an Activity from one application screen exits the foreground and an Activity from another application screen enters the foreground. The process of an Activity exiting the foreground and entering the foreground both trigger a full OomAdj calculation. In other words, during a single screen transition, a full OomAdj calculation is triggered twice.

[0176] During a full OomAdj calculation, the OomAdjuster component traverses all application processes and the processes associated with each application process. Because there are multiple application processes in the system, and these processes are interconnected, each full OomAdj calculation involves complex traversal, resulting in a large amount of data processing and increasing system load.

[0177] In some application scenarios, when a user browses different interfaces within the same application, the Activities of those different interfaces within the same application switch to the foreground.

[0178] As an example, such as Figure 4 The image shown is a schematic diagram of the chat application interface. Figure 4 The interface 40 shown in (a) includes a chat list, which contains multiple chat objects and each chat object's avatar and username (such as "User 1", "User 2", and "User 3"). When a user clicks on the avatar or username of "User 1", in response to that user's action, the electronic device jumps to, for example,... Figure 4 Interface 41, shown in (b) above, is the chat interface between the user of the electronic device and the chat partner "User 1". In... Figure 4 The interface 41 shown in (b) includes the chat content between the user of the electronic device and the chat partner "User 1". When the user clicks the control 411 in the interface 41, in response to the user's operation, the electronic device jumps to, as shown in (b). Figure 4 Interface 40 is shown in (a) of the diagram.

[0179] Figure 4 Interface 40 shown in (a) and Figure 4 Interface 41 shown in (b) represents different interfaces of a chat application. Depending on user actions, the electronic device can... Figure 4 Interface 40 shown in (a) and Figure 4 The screen switches back and forth between interface 41 as shown in (b). Correspondingly, whenever interface 40 and interface 41 switch, the Activity corresponding to interface 40 and the Activity corresponding to interface 41 switch in the system foreground.

[0180] As another example, such as Figure 5 The image shown is a schematic diagram of the reading application's interface. Figure 5 The interface 50 shown in (a) includes a novel list, which contains multiple novels and each novel's cover image, name, and rating. For example, the novel named "Novel 1" has a rating of "8.0 points," and the novel "Novel 2" has a rating of "7.6 points." When the user clicks on the control area 511 corresponding to "Novel 1," in response to the user's action, the electronic device jumps to, for example,... Figure 5 The interface 51 shown in (b) is the details interface for "Novel 1". Figure 5 The interface 51 shown in (b) includes detailed information such as a synopsis and table of contents for "Novel 1". When the user clicks the control 512 in interface 51, the electronic device jumps to the following in response to the user's action: Figure 5 Interface 50 is shown in (a) of the diagram.

[0181] Figure 5 Interface 50 shown in (a) and Figure 5 Interface 51 shown in (b) represents different interfaces of the reading application. Depending on user actions, the electronic device can... Figure 5 Interface 50 shown in (a) and Figure 5 The screen switches back and forth between interface 51 as shown in (b). Correspondingly, whenever interface 50 and interface 51 switch, the Activity corresponding to interface 50 and the Activity corresponding to interface 51 switch in the system foreground.

[0182] It should be noted that, Figure 4 and Figure 5 These are merely examples of different interfaces within the same application; the embodiments in this application do not specifically limit the application interface.

[0183] In the above application scenario, when Activities on different screens of the same application switch to the foreground, the adjustment score oom_adj of the application remains unchanged because the order of the application processes remains the same, and the adjustment scores oom_adj of other application processes also remain unchanged. However, when switching between different screens of the same application, where an Activity from one application screen exits the foreground and an Activity from another application screen enters the foreground, the system still performs two full OomAdj calculations, causing a large amount of redundant load on the system.

[0184] Based on this, this application provides a memory management method that intercepts the full calculation of OomAdj during the switching of the interface of the same application, thereby effectively reducing the system load.

[0185] See Figure 6 This is a schematic diagram of the interaction flow of the memory management method provided in the embodiments of this application.

[0186] like Figure 6 As shown in (a), the process of stopping an Activity may include the following steps:

[0187] S601, when an Activity is stopped, the Transition component executes the OnStop() method.

[0188] S602, during the execution of the OnStop() method, Transition calls the ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method in ActivityTaskSupervisor.

[0189] S603, in the ScheduleProcessStoppingAndFinishingActivitiesIfNeeded method, ActivityTaskSupervisor executes the ScheduleIdle method.

[0190] S604 triggers the IDLE_NOW_MSG message.

[0191] S605, after ActivityTaskSupervisor triggers the IDLE_NOW_MSG message, ActivityTaskSupervisor executes the ActivityIdleInternal method.

[0192] Steps S601-S605 are the same as steps S301-S305, and can be found in the description of steps S301-S305 in the embodiments, which will not be repeated here.

[0193] S606, in the ActivityIdleInternal method, ActivityTaskSupervisor calls the ATMS judgment method.

[0194] In this embodiment of the application, a judgment method is added to ATMS, and the code logic of calling the judgment method and intercepting or executing trimApplication according to the judgment method is added to ActivityTaskSupervisor.

[0195] S607, in the judgment method, ActivityTaskManagerService obtains the previous Activity that was in the foreground.

[0196] In this embodiment of the application, it is necessary to save the Activity that enters the foreground for subsequent judgment method calls.

[0197] In one implementation, a memory variable can be set to record the Activity that was previously in the foreground. After each execution of the judgment method, the value of the memory variable (i.e., the Activity that was previously in the foreground) is replaced with the Activity that is currently in the foreground.

[0198] For example, after S609, i.e., after ActivityTaskSupervisor receives the judgment result, the memory variable can be replaced with the currently foreground Activity. This method requires adding corresponding code logic to ActivityTaskManagerService. Alternatively, the value of the memory variable can be updated after the judgment step in S608. This method requires adding corresponding code logic to the judgment method in ATMS. The specific implementation method can be set according to development needs; this embodiment does not impose specific limitations.

[0199] S608, ActivityTaskManagerService determines whether the previous foreground Activity and the currently foreground Activity belong to the same application.

[0200] During the execution of the judgment method, ActivityTaskManagerService can obtain relevant information about the Activity from the window management module WindowManager. For example, ActivityTaskManagerService retrieves the Task object at the top of the stack from the root window container component RootWindowContainer in the window management module. The Task object is an Activity stack, which follows a Last-In-First-Out (LIFO) stack, meaning that messages added earlier are processed later, and messages added later are processed first. The Activity at the top of the stack (the last Activity added) from the retrieved Task object is the Activity currently in the foreground.

[0201] Additionally, ActivityTaskManagerService can retrieve information about the application to which the currently foreground Activity belongs from the window management module. For example, it can retrieve the topActivity.app variable from the window management module, which represents information about the application to which the currently foreground Activity belongs. If the topActivity.app variables of two Activities have the same key value, it means that the two Activities belong to the same application; if the topActivity.app variables of two Activities have different key values, it means that the two Activities belong to different applications.

[0202] S609, ActivityTaskManagerService returns the judgment result to ActivityTaskSupervisor.

[0203] In one implementation, if the previous foreground Activity and the current foreground Activity belong to the same application, the judgment result is True; if the previous foreground Activity and the current foreground Activity belong to different applications, the judgment result is False.

[0204] It should be noted that in practical applications, other flags or information can be used to represent different judgment results. For example, if the previous foreground Activity and the current foreground Activity belong to the same application, the judgment result is 1; if the previous foreground Activity and the current foreground Activity belong to different applications, the judgment result is 0. As another example, if the previous foreground Activity and the current foreground Activity belong to the same application, the judgment result includes the flag bit; if the previous foreground Activity and the current foreground Activity belong to different applications, the judgment result does not include the flag bit. This application does not specifically limit this aspect.

[0205] If the judgment result is False, execute S611-S612; if the judgment result is True, execute S610.

[0206] S610: After receiving the judgment result returned by ActivityTaskManagerService, if the judgment result is True, ActivityTaskSupervisor intercepts the trimApplication process.

[0207] In one interception method, if the judgment result is True, "return" is executed, and the ActivityIdleInternal method is exited, that is, the trimApplication method is skipped, thereby achieving the interception of the trimApplication method.

[0208] S611, after receiving the judgment result returned by ActivityTaskManagerService, if the judgment result is False, ActivityTaskSupervisor calls the trimApplication method of AMS.

[0209] In S612, AMS calls the OomAdj method in OomAdjuster in the trimApplication method to perform a full calculation of OomAdj.

[0210] Steps S611-S612 are the same as steps S306-S307, and can be found in the description of the embodiments in S306-S307.

[0211] like Figure 6 As shown in (b), the process of starting an Activity may include the following steps:

[0212] S613, when the system receives an Activity resume message, ActivityThread executes the OnResume() method.

[0213] S614, in the OnResume() method, ActivityThread generates the resume message for the Activity that is about to be launched.

[0214] S615, ActivityThread puts the resume message into the queue.

[0215] S616 processes the resume message of the Activity to be launched that is in the queue.

[0216] S617, ActivityThread calls the ActivityIdle method in ActivityTaskSupervisor through ActivityClientController.

[0217] S618, in the ActivityIdle method, ActivityTaskSupervisor executes the ActivityIdleInternal method.

[0218] Steps S613-S618 are the same as steps S308-S313, and can be found in the description of the embodiments in S308-S313, which will not be repeated here.

[0219] After S618, execute S606-S612.

[0220] like Figure 6 As shown in the embodiment of this application, the memory management method sets a judgment method in ActivityTaskManagerService. During the execution of the ActivityIdleInternal method by ActivityTaskSupervisor, the judgment method in ActivityTaskManagerService is called before the trimApplication method is invoked, and the trimApplication method is executed or intercepted based on the judgment result returned by ActivityTaskManagerService. In this way, when the Activities before and after the switch belong to the same application, the full calculation of OomAdj can be intercepted, thereby effectively reducing system load.

[0221] In addition, from Figure 6As can be seen from the embodiments of this application, memory management during Activity switching can be achieved and system load reduced by simply adding relevant logic code for the judgment method in ActivityTaskManagerService and relevant logic code for calling the judgment method and executing or intercepting trimApplication based on the judgment result in ActivityTaskSupervisor. This approach involves relatively low code development difficulty and is easy to implement.

[0222] For example, see Figure 7 This is a schematic diagram of an Activity switching scenario provided in an embodiment of this application. Figure 7 As shown, the electronic device switches from interface A to interface B, then back to interface A, and finally to interface D. The active component of interface A is Activity A, the active component of interface B is Activity B, and the active component of interface D is Activity D. Interfaces A and B belong to the same application, while interfaces A and D belong to different applications.

[0223] The process of switching from interface A to interface B includes the process of stopping Activity A (Stop A) and the process of starting Activity B (Resume B).

[0224] The process of Stop A can be found in [reference]. Figure 6 The process is shown in (a) above. The process of ActivityTaskManagerService calling the judgment method is as follows: Figure 8 As shown in (a), the currently foreground Activity is retrieved, i.e., Activity A. Retrieving the previously foreground Activity can be understood as follows: before Stop A, the Resume A process occurred. As described in S607, after the judgment method was executed during Resume A, the memory variable was updated. That is, when Stop A was executed, the memory variable was Activity A, meaning the previously foreground Activity was Activity A. In this case, the previously foreground Activity is the same as the currently foreground Activity, so OomAdj is intercepted, and there is no need to update the memory variable.

[0225] The ResumeB process can be found in [link / reference]. Figure 6 The process is shown in (b) above. The process of ActivityTaskManagerService calling the judgment method is as follows: Figure 8As shown in (b), get the Activity that is currently in the foreground, i.e. Activity B; get the Activity that was in the foreground last time, i.e. Activity A; determine whether Activity A and Activity B belong to the same application; as can be seen from the above scenario, Activity A and Activity B belong to the same application, so intercept OomAdj and record the Activity that is currently in the foreground as the Activity that was in the foreground last time.

[0226] As can be seen from the above process, during the switch from interface A to interface B, since interface A and interface B belong to the same application, the calls to the `trimApplication` method in AMS during the `Stop A` and `Resume B` processes can be intercepted, thereby intercepting the full calculation of `OomAdj`. Figure 7 As shown, this reduces the two full OomAdj calculations during the switching process between interface A and interface B, thereby reducing the system load.

[0227] Understandably, in the above application scenario, if switching back from interface B to interface A, during the Stop B process, since both the previously foreground Activity and the currently foreground Activity are Activity B (meaning they belong to the same application), OomAdj is intercepted, and the previously foreground Activity remains unchanged. During the Resume A process, the previously foreground Activity is Activity B, and the currently foreground Activity is Activity A. Both activities belong to the same application, so OomAdj is intercepted, and the currently foreground Activity A is recorded as the previously foreground Activity. For example... Figure 7 As shown, OomAdj was intercepted twice during the switch from interface B to interface A.

[0228] As can be seen from the above examples, when switching repeatedly between different interfaces in the same application, the method in this application can reduce the calculation of the full OomAdj involved in the switching process, thereby reducing the system load.

[0229] like Figure 7 As shown, the process of switching from interface A to interface D includes stopping Activity A (StopA) and starting Activity D (ResumeD). The Stop A process is the same as the Stop A process during the switch from interface A to interface B, and will not be described again. The Resume D process can be found in [link to documentation]. Figure 6 The process is shown in (b). Specifically, get the currently foreground Activity, i.e., Activity D; get the previously foreground Activity, i.e., Activity A; determine whether Activity A and Activity D belong to the same application; as can be seen from the above scenario, Activity A and Activity D belong to different applications, so execute OomAdj, and record the currently foreground Activity D as the previously foreground Activity.

[0230] As can be seen from the above examples, when switching between different interfaces of different applications, the method in this application can still perform full OomAdj calculation normally, so as to effectively manage system memory.

[0231] The above embodiments describe the full-screen display of the application interface. In other application scenarios, electronic devices can display the application interface in a non-full-screen manner. For example, an electronic device can display multiple application interfaces in a split-screen format or display different application interfaces in multiple windows. In the case of non-full-screen display, multiple application interfaces are displayed on the screen simultaneously, so determining whether the Activity before and after the switch belongs to the same application involves judging multiple applications.

[0232] Considering the above, in one embodiment, it is necessary to first determine whether it is a full-screen display. See details... Figure 9 This is a schematic diagram of the interaction flow of a memory management method provided in another embodiment of this application. For example... Figure 9 As shown in (a), this is the process of stopping an Activity. When an Activity is stopped, the following steps are executed:

[0233] Execute S601-S606.

[0234] For details of steps S601-S606, please refer to [link / reference]. Figure 6 The descriptions in the embodiments will not be repeated here.

[0235] S901, in the ActivityIdleInternal method, ActivityTaskSupervisor calls the ATMS judgment method.

[0236] S902, in the judgment method, ActivityTaskManagerService determines whether the current display is full screen.

[0237] If the display is in full screen, execute steps S903-S904. If the display is not in full screen, execute steps S905-S906.

[0238] As described in S608, information about the currently foreground Activity can be obtained from the Task object. The Task object can be a tree structure, where nodes represent Activities. The topmost node in the tree represents the currently foreground Activity, and its child nodes represent the previous foreground Activity. If the same level in the tree structure contains only one node, it indicates that one Activity exists in the foreground, i.e., full-screen display; if the same level in the tree structure contains multiple nodes, it indicates that multiple Activities exist simultaneously in the foreground, i.e., non-full-screen display.

[0239] Based on this, in one implementation of S902, the number of topmost Activities in the Task object is detected; if the number of topmost Activities is 1, it is determined to be full-screen display; if the number of topmost Activities is greater than 1, it is determined to be non-full-screen display.

[0240] S903, ActivityTaskManagerService retrieves the previous foreground Activity.

[0241] S904, ActivityTaskManagerService determines whether the previous foreground Activity and the currently foreground Activity belong to the same application.

[0242] Steps S903-S904 are the same as steps S607-S608, and can be referred to the description in the embodiments of S607-S608 for details, which will not be repeated here.

[0243] S905, ActivityTaskManagerService retrieves multiple Activities that were previously in the foreground.

[0244] As described in S607, in this embodiment of the application, it is necessary to save the Activity that entered the foreground for subsequent judgment method calls. It can be understood that if there were multiple Activities that were in the foreground last time, the memory variable includes all of the Activities that were in the foreground last time.

[0245] S906, ActivityTaskManagerService determines whether the multiple Activities that were previously in the foreground are in the same position as the Activity that is currently in the foreground and belong to the same application.

[0246] Understandably, S906 involves two judgment processes: whether the positions are the same and whether they belong to the same application.

[0247] As described in S608, relevant information about an Activity can be obtained from the WindowManager module.

[0248] For example, the `topActivity.app` variable can be retrieved from the window management module. This variable represents information about the application to which the currently foreground Activity belongs. If the key values ​​of the `topActivity.app` variables of two Activities are the same, it means that the two Activities belong to the same application; if the key values ​​of the `topActivity.app` variables of two Activities are different, it means that the two Activities belong to different applications.

[0249] For example, the `Activity.local` variable can be retrieved from the window management module. This variable represents the position information of the Activity on the screen. If the key values ​​of the `Activity.local` variables of two Activities are the same, it means that the two Activities are in the same position; if the key values ​​of the `Activity.local` variables of two Activities are different, it means that the two Activities are in different positions.

[0250] One method for determining this is as follows: For any one of the previously foreground Activities (Activity 1) and the currently foreground Activity (Activity 2), check the `Activity.local` variable to see if Activity 1 and Activity 2 are in the same position. If Activity 1 and Activity 2 are in different positions, then retrieve another Activity 3 from the previously foreground Activities (excluding Activity 1) and check if Activity 3 is in the same position as Activity 2. If the position of each of the previously foreground Activities is different from the position of Activity 2, the result is False. If the position information of Activity 1 and Activity 2 is the same, then check the `Activity.app` variable to see if Activity 1 and Activity 2 belong to the same application. If Activity 1 and Activity 2 belong to the same application, then determine that the previously foreground Activity in region X and the currently foreground Activity belong to the same application, and the result is True. If Activity 1 and Activity 2 belong to different applications, then determine that the previously foreground Activity in region X and the currently foreground Activity belong to different applications, and the result is False. Here, region X is the display area corresponding to the position information of Activity 1 and Activity 2.

[0251] It should be noted that if the number of Activities currently in the foreground is greater than 1, the determination is made based on the Activity corresponding to the currently executed method (such as the Stop / Resume Activity method).

[0252] For example, during the Stop A process, the currently foreground Activity includes Activity A. The judgment is performed on each Activity. Specifically, S906 checks if the Activity.local variable of each previously foreground Activity is the same as the Activity.local variable of Activity A. If the Activity.local variable of Activity 1 (previously foreground) is the same as the Activity.local variable of Activity A, it means that Activity 1 and Activity A are in the same position. Then, it checks if the Activity.app variable of Activity 1 is the same as the Activity.app variable of Activity A. If the Activity.app variable of Activity 1 is the same as the Activity.app variable of Activity A, then it is determined that Activity 1 and Activity A are in the same position and belong to the same application. That is, the previously foreground Activity and the currently foreground Activity in region Y belong to the same application, and the judgment result is True. Here, region Y is the display area corresponding to Activity A and Activity 1. If the Activity.app variable of Activity 1 is different from the Activity.app variable of Activity A, then it is determined that Activity 1 and Activity A are in the same application. 1. Activity A and Activity B belong to different applications. That is, the Activity that was previously in the foreground in region Y and the Activity that is currently in the foreground belong to different applications. The result of the judgment is False.

[0253] For example, during the Resume B process, the currently foreground Activity includes Activity B. When performing a check on Activity B, S906 is executed as follows: It checks if the Activity.local variable of each previously foreground Activity is the same as the Activity.local variable of Activity B. If the Activity.local variable of Activity 2 (a previously foreground Activity) is the same as the Activity.local variable of Activity B, it means that Activity 2 and Activity A are in the same position. Then, it checks if the Activity.app variable of Activity 2 is the same as the Activity.app variable of Activity B. If the Activity.app variable of Activity 2 is the same as the Activity.app variable of Activity B, then it is determined that Activity 2 and Activity B are in the same position and belong to the same application. That is, the previously foreground Activity and the currently foreground Activity in region Z belong to the same application, and the result is True. Region Z is the display area corresponding to Activity B and Activity 2. If the Activity.app variable of Activity 2 is different from the Activity.app variable of Activity B, then it is determined that Activity B is not in the same position. 2. Activity B and Activity B belong to different applications. That is, the Activity that was previously in the foreground in region Z and the Activity that is currently in the foreground belong to different applications. The result of the judgment is False.

[0254] S907, ActivityTaskManagerService returns the judgment result to ActivityTaskSupervisor.

[0255] In one scenario, when switching from full-screen to non-full-screen display, or vice versa, the number of Activities that were previously in the foreground differs from the current number, and their corresponding display areas also differ. In this case, ActivityTaskManagerService returns False to ActivityTaskSupervisor. If the number of Activities that were previously in the foreground is the same as the current number, then S903-S904 or S905-S906 is executed based on the number of Activities in the foreground.

[0256] In one scenario, when the display is not full-screen, if the Activity in a portion of the display area does not switch, the Stop Activity and Resume Activity methods will not be executed in that display area. Consequently, there is no need to execute the judgment method for the Activity in that display area.

[0257] If the judgment result is True, then execute S908; if the judgment result is False, then execute S909-S910.

[0258] S908, if the judgment result is True, ActivityTaskSupervisor intercepts the trimApplication process.

[0259] S909, if the judgment result is False, ActivityTaskSupervisor calls the trimApplication method of AMS.

[0260] In S910, AMS calls the OomAdj method in OomAdjuster in the trimApplication method to perform a full calculation of OomAdj.

[0261] Steps S909-S910 are the same as steps S611-S612, and can be referred to the description in the embodiments of S611-S612 for details, which will not be repeated here.

[0262] like Figure 9 As shown in (b), this is the process of starting an Activity. When the system receives an Activity resume message, it executes steps S613-S619, and then steps S901-S910. Specific details involved in the execution process can be found in the descriptions of embodiments S613-S619 and S901-S910, and will not be repeated here.

[0263] It should be noted that, as described in embodiment S607, a memory variable is set to record the Activity that was previously in the foreground, and the judgment method needs to be called from ActivityTaskManagerService each time the method to start / stop an Activity is executed. In full-screen display scenarios, each screen switch only involves one Stop process and one Resume process, so the memory variable can be updated after each execution of the judgment method. For example, after S609 (i.e., after ActivityTaskSupervisor receives the judgment result), the memory variable can be replaced with the currently foreground Activity. However, in non-full-screen display scenarios, each screen switch may involve multiple Stop processes and multiple Resume processes. If the memory variable is updated after each execution of the judgment method during a Stop / Resume process, it may lead to judgment errors.

[0264] For example, the previously foreground Activities included Activity 1 and Activity 2, while the currently foreground Activities include Activity 3 and Activity 4. During the Resume of Activity 3, the memory variable contains Activity 1 and Activity 2. If the memory variable is updated after executing the judgment method, then during the Resume of Activity 4, the memory variable will be updated to Activity 3 and Activity 4. However, in reality, during the Resume of Activity 4, the previously foreground Activities are still Activity 1 and Activity 2. After the memory variable is updated to Activity 3 and Activity 4, the judgment method during the Resume of Activity 4 checks whether the previously foreground Activities Activity 3 and Activity 4 are in the same position and belong to the same application as the currently foreground Activity 4. Obviously, the judgment result is incorrect.

[0265] To avoid the above situation, optionally, for each interface switching process, after each execution of the judgment method in ActivityTaskManagerService, it is determined whether the current Stop / Resume process is the last Stop / Resume process in the current interface switching process; if so, the memory variable is updated; if not, the memory variable is not updated.

[0266] For example, the previously foreground Activities included Activity 1 and Activity 2, while the currently foreground Activities include Activity 3 and Activity 4. During the Stop of Activity 1 process, after executing the judgment method, it is determined whether the current Stop process is the last Stop process in the current screen transition; if not, the memory variable is not updated. During the Stop of Activity 2 process, after executing the judgment method, it is determined whether the current Stop process is the last Stop process in the current screen transition; if yes, the memory variable is updated, i.e., the updated memory variable contains Activity 1 and Activity 2. During the Resume of Activity 3 process, after executing the judgment method, it is determined whether the current Resume process is the last Resume process in the current screen transition; if not, the memory variable is not updated, i.e., the memory variable still contains Activity 1 and Activity 2. During the Resume of Activity 4 process, after executing the judgment method, it is determined whether the current Resume process is the last Resume process in the current screen transition; if yes, the memory variable is updated, i.e., the updated memory variable contains Activity 3 and Activity 4.

[0267] In one implementation, determining whether the current Stop process is the last Stop process in the current interface switching process can be done by: obtaining the number of Activities that were in the foreground last time; and determining whether the current Stop process is the last Stop process in the current interface switching process based on the number of Stop processes that have been executed in the current interface switching process and the number of Activities that were in the foreground last time.

[0268] In one implementation, determining whether the current Resume process is the last Resume process in the current interface switching process can be done by: obtaining the number of Activities currently in the foreground; and determining whether the current Resume process is the last Resume process in the current interface switching process based on the number of Resume processes that have been executed in the current interface switching process and the number of Activities that were in the foreground last time.

[0269] For example, set counters for the Stop and Resume processes respectively. Reset both counters each time a UI switch command is received. Increment the corresponding counter by 1 each time a Stop / Resume process is executed. The counter value represents the number of times the Stop / Resume process has been executed during the current UI switch.

[0270] and Figure 6 Compared to the interactive flow shown, Figure 9The interactive flow shown has been updated with logic to determine whether the display is in full-screen mode and logic to determine whether the display is not in full-screen mode.

[0271] Understandably, the added judgment method is added to ActivityTaskManagerService. During the process of stopping or starting an Activity, ActivityTaskSupervisor calls the judgment method in ActivityTaskManagerService. Therefore, the judgment method is for the full calculation of OomAdj involved in the current stopping / starting of the Activity.

[0272] For example, during the Stop A process, the judgment method targets the full OomAdj calculation involved in Stop A. Specifically, it checks whether the multiple Activities that were previously in the foreground are in the same position as Activity A and belong to the same application; if the judgment result is True, ActivityTaskSupervisor intercepts the call to trimApplication process during Stop A, that is, it intercepts the full OomAdj calculation during Stop A; if the judgment result is False, ActivityTaskSupervisor calls the trimApplication method of AMS during Stop A, that is, it executes the full OomAdj calculation during Stop A.

[0273] During the Resume B process, the judgment method targets the full OomAdj calculation involved in the Stop B process. Specifically, it checks whether the multiple Activities that were previously in the foreground are in the same position as Activity B and belong to the same application. If the judgment result is True, ActivityTaskSupervisor intercepts the call to trimApplication process during the Resume B process, that is, it intercepts the full OomAdj calculation during the Resume B process. If the judgment result is False, ActivityTaskSupervisor calls the trimApplication method of AMS during the Resume B process, that is, it executes the full OomAdj calculation during the Resume B process.

[0274] Non-full-screen display scenarios can include top-and-bottom split-screen display, left-and-right split-screen display, and multi-window display. The following sections will introduce various non-full-screen display scenarios as examples. Figure 9 The aforementioned interaction process.

[0275] As an example of split-screen display, see Figure 10 This is a schematic diagram illustrating the Activity switching scenario in a split-screen environment provided in an embodiment of this application. For example... Figure 10 As shown, the electronic device displays a split-screen interface, with the display screen comprising two display areas (Area 1 and Area 2). In interface AB, Area 1 displays interface A, and Area 2 displays interface B. In interface CD, Area 1 displays interface C, and Area 2 displays interface D. The active component of interface A is Activity A, the active component of interface B is Activity B, the active component of interface C is Activity C, and the active component of interface D is Activity D. Interfaces A and C belong to the same application, and interfaces B and D belong to the same application.

[0276] The process of switching from interface AB to interface CD includes stopping Activity A (Stop A), stopping Activity B (Stop B), starting Activity C (Resume C), and starting Activity D (Resume D).

[0277] The process of Stop A and Stop B can be found in [reference]. Figure 9 The process is shown in (a). During the Stop A and Stop B processes, steps S901-S902 and S905-S906 are executed because the current display screen is split-screen.

[0278] During the Stop A process, the judgment method's flow includes: obtaining the currently foreground Activity, i.e., Activity A and Activity B; and obtaining the previously foreground Activity. This can be understood as follows: before Stop A, there were Resume A and Resume B processes. After the judgment method is executed during Resume B, the memory variables are updated. That is, when Stop A is executed, the memory variables contain Activity A and Activity B, meaning the previously foreground Activities were Activity A and Activity B. Essentially, if the previously foreground Activity and the currently foreground Activity are in the same position and have the same Activity, then OomAdj is intercepted, and there's no need to update the memory variables.

[0279] During the Stop B process, the execution logic of the judgment method is the same as that of the judgment method in Stop A, and will not be repeated here. Since Stop B is the last Stop process in this switch, after Stop B or after executing the judgment method during Stop B, the memory variables are updated, that is, the currently foreground Activity A and Activity B are recorded as the previously foreground Activity.

[0280] The processes for Resume C and Resume D can be found in [link to documentation]. Figure 9 The process is shown in (b) above. During Resume C and Resume D, steps S901-S902 and S905-S906 are executed because the current display screen is split-screen.

[0281] In the Resume C process, the method selection process is as follows: Figure 11 As shown. The currently foreground Activities are retrieved, namely Activity C and Activity D; since Resume C is currently executing, the process is determined based on Activity C. Specifically, the previously foreground Activities are retrieved, namely Activity A and Activity B. It is determined whether the previously foreground Activities are in the same position as Activity C and whether they belong to the same application (the determination method is as described in embodiment S906); according to... Figure 10 In the application scenario shown, Activity A and Activity C are in the same location (both belong to region 1), and Activity A and Activity C belong to the same application. That is, the Activity that was previously in the foreground in region 1 and the Activity that is currently in the foreground belong to the same application, so the judgment result is True. Based on this judgment result, OomAdj is intercepted during the Resume C process.

[0282] During the Resume D process, the decision-making process is as follows: Figure 11 As shown. The currently foreground Activities are retrieved, namely Activity C and Activity D; since Resume D is currently executing, the process is determined based on Activity D. Specifically, the previously foreground Activities are retrieved, namely Activity A and Activity B. It is determined whether the previously foreground Activities are in the same position as Activity D and whether they belong to the same application (the determination method is as described in embodiment S906); according to... Figure 10In the application scenario shown, Activity B and Activity D are in the same position (both belong to region 2), and Activity B and Activity D belong to the same application. That is, the Activity that was previously in the foreground in region 2 and the Activity that is currently in the foreground belong to the same application, so the judgment result is True. Based on this judgment result, OomAdj is intercepted during the Resume D process. Since Resume D is the last Resume process executed during this interface switch, the memory variable can be updated after Resume D or after the judgment method is executed during Resume D, that is, the Activity C and Activity D that are currently in the foreground are recorded as the Activity that was previously in the foreground.

[0283] As can be seen from the above process, in the case of split-screen display, the Activity that was previously in the foreground and the Activity that is currently in the foreground in both display areas belong to the same application. Therefore, it is possible to intercept the `trimApplication` method in AMS during the `Resume C` and `Resume D` processes (such as...). Figure 10 The call to the tA method (as shown) intercepts the full computation of OomAdj. For example... Figure 10 As shown, the full OomAdj calculations for Resume C and Resume D are reduced during the switching process between interface A and interface C, and between interface B and interface D. This is equivalent to reducing two full OomAdj calculations, thereby reducing the system load.

[0284] It should be noted that in the above application scenarios, the judgment result needs to be determined based on the previous interface of interface A and interface B during the process of Stop A and Stop B. Since the judgment principle is the same, no specific examples will be given in this application embodiment.

[0285] Understandably, in the above application scenario, if switching from interface C to interface A or B includes the processes of Stop C, Stop D, Resume A, and Resume B. During Stop C and Stop D, since the previously foreground Activities were Activity C and Activity D, and the currently foreground Activities are still Activity C and Activity D, the full OomAdj calculation is intercepted during Stop C and Stop D, and the memory variables remain unchanged (the previously foreground Activities have not changed). During Resume A and Resume B, the previously foreground Activities were Activity C and Activity D, and the currently foreground Activities are Activity A and Activity B. Since Activity A and Activity C are in the same position and belong to the same application, and Activity B and Activity D are in the same position and belong to the same application, the full OomAdj calculation is intercepted during Resume A and Resume B. Figure 10 As shown, during the process of switching from interface CD to interface AB, four full OomAdj calculations were intercepted.

[0286] As can be seen from the above examples, when switching repeatedly between different interfaces in the same application, the method in this application can reduce the calculation of the full OomAdj involved in the switching process, thereby reducing the system load.

[0287] As another example of split-screen display, see [link to example]. Figure 12 This is a schematic diagram of Activity switching in a split-screen scenario provided in another embodiment of this application.

[0288] like Figure 12 As shown in (a), the electronic device displays a split-screen interface, with the display screen comprising two display areas (area 1 and area 2). In interface AB, area 1 displays interface A, and area 2 displays interface B. In interface AE, area 1 displays interface A, and area 2 displays interface E. The active component of interface A is Activity A, the active component of interface B is Activity B, and the active component of interface E is Activity E. Interfaces B and E belong to different applications.

[0289] Since the interface in area 1 does not change, the process of switching from interface AB to interface AE includes the process of stopping Activity B (Stop B) and starting Activity E (Resume E).

[0290] The process of Stop B can be found in [link / reference]. Figure 9 The process is shown in (a) above. During the Stop B process, because the current display screen is split-screen, steps S901-S902 and S905-S906 are executed. For details on the steps of the judgment method executed during the Stop B process, please refer to [link to relevant documentation]. Figure 10 The process of Stop B in the scenario where interfaces A and B switch to interfaces C and D will not be described in detail here. After Stop B or after executing the judgment method in Stop B, the memory variables are updated, that is, the currently foreground Activity A and Activity B are recorded as the previously foreground Activity.

[0291] The process of Resume E can be found in [link / reference]. Figure 9 The process is shown in (b) above. During Resume E, because the current display screen is split-screen, steps S901-S902 and S905-S906 are executed. The process of ActivityTaskManagerService calling the judgment method is as follows: Figure 13 As shown in (a), the currently foreground Activities are retrieved, namely Activity A and Activity E; since Resume E is currently executing, the process is determined based on Activity E. Specifically, the previously foreground Activities are retrieved, namely Activity A and Activity B. It is determined whether the previously foreground Activities and Activity E are in the same position and whether they belong to the same application (the determination method is as described in embodiment S906); according to... Figure 12 In the application scenario shown in (a), Activity B and Activity E are in the same position (both belong to area 2), but Activity B and Activity E belong to different applications. That is, the Activity that was previously in the foreground in area 2 and the Activity that is currently in the foreground belong to different applications, so the judgment result is False. Based on this judgment result, OomAdj is executed in the Resume E process. Since Resume E is the last Resume process executed during this interface switch, the memory variable can be updated after Resume E or after the judgment method is executed during Resume E, that is, the Activity A and Activity E that are currently in the foreground are recorded as the Activity that was previously in the foreground.

[0292] like Figure 12As shown in (a), the call to the trimApplication method (tA method) of AMS during the Resume E process was not intercepted, meaning the full OomAdj calculation during the Resume E process was not intercepted. In a scenario with split-screen display, if no interface switching occurs in one display area, but switching between different interfaces of different applications occurs in another display area, the full OomAdj calculation can still be performed normally according to the memory management method in this application, thereby effectively managing system memory.

[0293] like Figure 12 As shown in (b), the electronic device displays a split-screen interface, with the display screen comprising two display areas (area 1 and area 2). In interface AB, area 1 displays interface A, and area 2 displays interface B. In interface AD, area 1 displays interface A, and area 2 displays interface D. The active component of interface A is Activity A, the active component of interface B is Activity B, and the active component of interface D is Activity D. Interfaces B and D belong to the same application.

[0294] Since the interface in area 1 does not change, the process of switching from interface AB to interface AD ​​includes the process of stopping Activity B (Stop B) and starting Activity D (Resume D).

[0295] The process of Stop B and Figure 12 The Stop B process described in (a) is the same; see [link to relevant documentation] for details. Figure 12 The description in embodiment (a) is as follows.

[0296] The process of Resume D can be found in [link / reference]. Figure 9 The process is shown in (b) above. During Resume D, because the current display screen is split-screen, steps S901-S902 and S905-S906 are executed. The process of ActivityTaskManagerService calling the judgment method is as follows: Figure 13 As shown in (b), the currently foreground Activities are retrieved, namely Activity A and Activity D; since Resume D is currently executing, the process is judged based on Activity D. Specifically, the previously foreground Activities are retrieved, namely Activity A and Activity B. It is determined whether the previously foreground Activities and Activity D are in the same position and whether they belong to the same application (the judgment method is as described in embodiment S906); according to Figure 12In the application scenario shown in (b), Activity B and Activity D are in the same position (both belong to region 2), and Activity B and Activity D belong to the same application. That is, the Activity that was previously in the foreground in region 2 and the Activity that is currently in the foreground belong to the same application, so the judgment result is True. Based on this judgment result, OomAdj in the Resume D process is intercepted. Since Resume D is the last Resume process executed during this interface switch, the memory variable can be updated after Resume D or after the judgment method is executed during Resume D, that is, the Activity A and Activity D that are currently in the foreground are recorded as the Activity that was previously in the foreground.

[0297] like Figure 12 As shown in (b), in a scenario of split-screen display, if no interface switching occurs in one display area, but switching between different interfaces of the same application occurs in another display area, the memory management method in this application can still intercept the full OomAdj calculation during the interface switching process of the same application in a certain display area, thereby reducing the system load of split-screen display.

[0298] As an example of left-right split-screen, see Figure 14 This is a schematic diagram of the Activity switching scenario in a split-screen situation provided in this application embodiment.

[0299] like Figure 14 As shown, the electronic device displays a split-screen interface, with the display screen comprising two display areas (area 1 and area 2). In interface AB, area 1 displays interface A, and area 2 displays interface B. In interface CE, area 1 displays interface C, and area 2 displays interface E. The active component of interface A is Activity A, the active component of interface B is Activity B, the active component of interface C is Activity C, and the active component of interface E is Activity E. Interfaces A and C belong to the same application, while interfaces B and E belong to different applications.

[0300] The process of switching from interface A to interface C includes stopping Activity A (Stop A), stopping Activity B (Stop B), starting Activity C (Resume C), and starting Activity E (Resume E). Specifically, the processes of Stop A and Stop B in the split-screen display scenario are different from... Figure 10The Stop A and Stop B processes in the vertical split-screen scenario described in the embodiment are the same, and the Resume C process in the horizontal split-screen scenario is the same. Figure 10 The Resume C process in the vertical split-screen scenario described in the embodiment is the same. The Resume E process in the horizontal split-screen scenario is the same. Figure 12 The Resume E process is the same as that described in embodiment (a) in the split-screen scenario. See also [link to example]. Figure 10 Examples and Figure 12 The description in embodiment (a) is not repeated here.

[0301] like Figure 14 As shown, during the transition from interface AB to interface CE, three full OomAdj calculations can be intercepted. In a split-screen display scenario, the previously foreground Activity and the currently foreground Activity in one display area belong to the same application, while the previously foreground Activity and the currently foreground Activity in the other display area belong to different applications. In this case, according to Figure 9 The memory management method described in the embodiment can intercept the full OomAdj calculation during the switching process of the same application interface in a certain display area, while still performing the full OomAdj calculation during the switching process of different application interfaces in a certain display area. This not only effectively manages system memory, but also reduces the system load of split-screen display.

[0302] Continue as Figure 14 As shown, the process of switching from interface CE to interface AB includes stopping Activity C (StopC), stopping Activity E (StopE), starting Activity A (ResumeA), and starting Activity B (ResumeB). During Stop C and Stop E, since the previously foreground Activities were Activity C and Activity E, and the currently foreground Activities are still Activity C and Activity E, the full OomAdj calculation is intercepted during Stop C and Stop E, and the memory variables remain unchanged (the previously foreground Activities have not changed).

[0303] During Resume A, the previously foreground Activities were Activity C and Activity E, while the currently foreground Activities are Activity A and Activity B. Since Activity A and Activity C are in the same location and belong to the same application, the full OomAdj calculation during Resume A is intercepted. During Resume B, the previously foreground Activities were Activity C and Activity E, while the currently foreground Activities are Activity A and Activity B. Since Activity B and Activity E are in the same location but belong to different applications, the full OomAdj calculation during Resume B is performed.

[0304] like Figure 14 As shown, during the switch from interface CE to interface AB, three full OomAdj calculations were intercepted. In a split-screen display scenario, no interface switch occurred in one display area, while the previously foreground Activity and the currently foreground Activity in the other display area belonged to the same application. In this case, according to Figure 9 The memory management method described in the embodiment can still intercept the full OomAdj calculation in a certain display area during the switching process of the same application interface, thereby reducing the system load of split-screen display.

[0305] from Figure 14 As can be seen from the examples, the memory management method of this application can intercept the full OomAdj calculation when switching between different interfaces in the same application, so as to reduce the system load of split-screen display; while when switching between different interfaces in different applications, the full OomAdj calculation can still be performed to effectively manage system memory.

[0306] As an example of multi-window display, see Figure 15 This is a schematic diagram of the Activity switching scenario under multi-window display provided in the embodiments of this application.

[0307] like Figure 15As shown, the electronic device displays information in two windows, with the screen comprising two display areas (Window 1 and Window 2). In interface AB, Window 1 displays interface A, and Window 2 displays interface B. In interface CD, Window 1 displays interface C, and Window 2 displays interface D. The active component of interface A is Activity A, the active component of interface B is Activity B, the active component of interface C is Activity C, and the active component of interface D is Activity D. Interfaces A and C belong to the same application, and interfaces B and D belong to the same application.

[0308] The process of switching from interface A to interface C includes stopping Activity A (Stop A), stopping Activity B (Stop B), starting Activity C (Resume C), and starting Activity D (Resume D). In multi-window display mode, the processes of Stop A and Stop B are different from... Figure 10 The Stop A and Stop B processes in the split-screen scenario described in the embodiment are the same, and the Resume C and Resume D processes in the multi-window display scenario are the same. Figure 10 The Resume C and Resume D processes in the split-screen scenario described in the embodiment are the same. See details in [link to example]. Figure 10 The descriptions in the embodiments will not be repeated here.

[0309] like Figure 15 As shown, in a multi-window display scenario, if switching between different interfaces of the same application occurs within a certain window, according to... Figure 9 The memory management method described in the embodiment can intercept the full OomAdj calculation during the interface switching process in the window, thereby reducing the system load of multi-window display.

[0310] Continue as Figure 15 As shown, the interface CD switches to interface C, that is, it switches from multi-window display to full-screen display. This process includes the process of stopping Activity D (Stop D). During the Stop D process, since the previously foreground Activities were Activity C and Activity D, and the currently foreground Activity is Activity C, the number of foreground Activities is different from the current number, and the corresponding display areas are different. In this case, during the execution of Stop D, the entire OomAdj is calculated, and the memory variable is updated to Activity C.

[0311] It is understandable that switching from interface C to interface AC involves launching Activity A. During the Resume A process, since the previous foreground Activity was Activity C, and the current foreground Activities are Activity A and Activity C, the number of foreground Activities differs from the current number, and their corresponding display areas are different. In this case, the entire OomAdj value is calculated during the Resume A process, and the memory variables are updated to reflect Activity A and Activity C.

[0312] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0313] This application also provides a computer-readable storage medium storing a computer program that, when run on an electronic device, can implement the steps in the various method embodiments described above.

[0314] This application also provides a computer program product that, when run on an electronic device or a wireless router, enables the electronic device to perform the steps described in the various method embodiments above.

[0315] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to the first device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0316] This application also provides a chip, which includes a processor coupled to a memory. The processor calls a computer program stored in the memory to implement the steps of any method embodiment of this application. The chip can be a single chip or a chip module composed of multiple chips.

[0317] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0318] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0319] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A memory management method, characterized in that, include: When the electronic device displays the first interface, it detects the user's first operation, wherein the first operation is used to switch the first interface to the second interface, and the first interface and the second interface are different interfaces in the same application. In response to the first operation, the computing process is intercepted during the cessation of the first interface; wherein the computing process is used to obtain the adjustment score of each process in the system of the electronic device, the adjustment score representing the priority of the process in memory management; The computation process is intercepted during the startup of the second interface; After the second interface is launched, the second interface is displayed.

2. The method according to claim 1, characterized in that, The method further includes: When the electronic device displays the second interface, a second user action is detected, wherein the second action is used to switch the second interface back to the first interface; In response to the second operation, the computation process is intercepted during the cessation of the second interface; The computation process is intercepted during the startup of the first interface; After the first interface is launched, the electronic device displays the first interface.

3. The method according to claim 1, characterized in that, The method further includes: When the electronic device displays the first interface, it detects a third operation by the user, wherein the third operation is used to switch the first interface to the third interface, and the first interface and the third interface are different interfaces in different applications. In response to the third operation, the computing process is intercepted during the cessation of the first interface; The calculation process is executed during the startup of the third interface; After the third interface is launched, the third interface is displayed.

4. The method according to claim 1, characterized in that, The method further includes: When the electronic device displays the first interface and the fourth interface in split screen, it detects the user's fourth operation; wherein, the fourth operation is used to switch the first interface to the fifth interface and the fourth interface to the sixth interface, the first interface and the fifth interface are different interfaces in the same application, and the fourth interface and the sixth interface are different interfaces in the same application; In response to the fourth operation, the computing process is intercepted during the cessation of the first interface; Intercept the computation process during the process of stopping the fourth interface; The computation process is intercepted during the startup of the fifth interface; The computation process is intercepted during the startup of the sixth interface; After the fifth and sixth interfaces are launched, the fifth and sixth interfaces are displayed in a split-screen format, wherein the fifth interface is in the same position as the first interface on the display screen, and the sixth interface is in the same position as the fourth interface on the display screen.

5. The method according to claim 4, characterized in that, The method further includes: When the electronic device displays the fifth interface and the sixth interface in split screen, a fifth user operation is detected, wherein the fifth operation is used to switch the fifth interface to the first interface and the sixth interface to the fourth interface; In response to the fifth operation, the computation process is intercepted during the cessation of the fifth interface; Intercept the computation process during the cessation of the sixth interface; The computation process is intercepted during the startup of the first interface; The computation process is intercepted during the startup of the fourth interface; After the first interface and the fourth interface are launched, the first interface and the fourth interface are displayed in a split screen.

6. The method according to claim 4, characterized in that, The method further includes: When the electronic device displays the first interface and the fourth interface in a split-screen mode, a sixth user operation is detected; wherein, the sixth operation is used to switch the fourth interface to the seventh interface, and the fourth interface and the seventh interface are different interfaces in different applications; In response to the sixth operation, the computation process is intercepted during the cessation of the fourth interface; The computation process is executed during the startup of the seventh interface; After the seventh interface is launched, the first interface and the seventh interface are displayed in a split screen, wherein the seventh interface and the fourth interface are in the same position on the display screen.

7. The method according to claim 4, characterized in that, The method further includes: When the electronic device displays the first interface and the fourth interface in a split-screen mode, a seventh user operation is detected; wherein, the seventh operation is used to switch the first interface to the fifth interface and the fourth interface to the eighth interface; the fourth interface and the eighth interface are different interfaces in different applications; In response to the seventh operation, the computation process is intercepted during the cessation of the first interface; Intercept the computation process during the process of stopping the fourth interface; The computation process is intercepted during the startup of the fifth interface; The computation process is executed during the startup of the eighth interface; After the fifth and eighth interfaces are launched, the fifth and eighth interfaces are displayed in a split-screen format, wherein the fifth interface and the first interface are in the same position on the display screen, and the fourth interface and the eighth interface are in the same position on the display screen.

8. The method according to claim 4, characterized in that, The method further includes: When the electronic device displays the first interface and the fourth interface in a split-screen mode, the user's eighth operation is detected; wherein, the eighth operation is used to switch the split-screen display to a full-screen display. In response to the eighth operation, the computation process is executed during the cessation of the fourth interface; After the fourth interface is stopped, the first interface is displayed in full screen.

9. The method according to claim 1, characterized in that, The method further includes: When the electronic device displays the first interface, it detects the user's ninth operation; wherein the ninth operation is used to switch the full-screen display to a split-screen display; In response to the ninth operation, the computation process is executed during the startup of the ninth interface; After the ninth interface is launched, the first interface and the ninth interface are displayed in a split screen.

10. An electronic device, characterized in that, The electronic device includes a processor for running a computer program stored in a memory to implement the method as claimed in any one of claims 1 to 9.

11. A chip system, characterized in that, The chip system includes a processor coupled to a memory, the processor being configured to run a computer program stored in the memory to implement the method as described in any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by one or more processors, implements the method as described in any one of claims 1 to 9.