Method, device and equipment for foreground and background switching processing of application

By creating and cacheing layer and frame data during cold startup of the application, directly displaying hidden layers and using retained frame data during hot startup, it solves the problem of frequent front and backend switching of the application, improving the switching speed and avoiding waste of resources.

CN119847754APending Publication Date: 2025-04-18GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites -1 Cited by

Patent Information

Application Number
CN202411944551.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

When the existing technology frequently goes back to the backend and then returns to the foreground, it is necessary to recreate the layer and frame data cache area, which makes it take a long time.

Method used

Create layers and cache frame data when applied cold start operations, hide layers and retain buffers for the last frame data when back-start, and directly display hidden layers and use retained frame data when hot start.

Benefits of technology

It shortens the time-consuming process caused by recreating layers and frame data, improves the speed of front and back-end switching of applications, and avoids waste of resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847754A_ABST
    Figure CN119847754A_ABST
Patent Text Reader

Abstract

The invention discloses a foreground and background switching processing method and device for an application and equipment, and the method comprises the steps: controlling a window management service to request a graph synthesis module to create a first graph layer for the first application under the condition that a cold start operation of the first application is detected; controlling the window management service to set the first layer in a display state; controlling the first application to request M buffer areas from an operating system, wherein the buffer areas are used for caching frame data used when the graph synthesis module performs graph synthesis; m is an integer greater than or equal to 2; when it is detected that the first application is switched from the foreground to the background, controlling the window management service to set the first layer to be in a hidden state; and controlling the first application to retain the buffer area in which the last frame of data is cached, and clearing the rest of the buffer areas.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to processing technology, and more particularly to a method, device and equipment for processing foreground and background switching of an application. Background Art

[0002] Currently, when an application exits the background, the layer corresponding to the application is destroyed, the drawing instruction set of the application interface is cleared, and the frame data cache of the application interface is cleared. When the application returns to the foreground again, it is necessary to recreate the layer of the application, build the drawing instruction set of the application interface, and apply for the frame data cache. Among the above operations, calling the destruction and creation of the layer, rebuilding the drawing instruction set, and applying for the frame data cache are all relatively time-consuming operations. For desktop applications that frequently exit the background and return to the foreground, the overall time consumption is relatively long. Summary of the invention

[0003] The present application provides a method, device and equipment for processing foreground and background switching of an application.

[0004] The technical solution of this application is implemented as follows:

[0005] In a first aspect, a method for processing foreground and background switching of an application is provided, the method comprising:

[0006] When a cold start operation of the first application is detected, controlling the window management service to request the graphics composition module to create a first layer for the first application;

[0007] Controlling the window management service to set the first layer to a display state;

[0008] Control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module when performing graphics synthesis; M is an integer greater than or equal to 2;

[0009] When detecting that the first application switches from the foreground to the background, controlling the window management service to set the first layer to a hidden state;

[0010] The first application is controlled to retain the buffer that caches the last frame of data and clear the remaining buffers.

[0011] In a second aspect, a device for processing foreground and background switching of an application is provided, the device comprising:

[0012] A control unit, configured to control the window management service to request the graphics synthesis module to create a first layer for the first application when a cold start operation of the first application is detected;

[0013] The control unit is further used to control the window management service to set the first layer to a display state;

[0014] The control unit is further used to control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module when performing graphics synthesis; M is an integer greater than or equal to 2;

[0015] The control unit is further configured to control the window management service to set the first layer to a hidden state when detecting that the first application switches from the foreground to the background;

[0016] The control unit is further used to control the first application to retain the buffer that caches the last frame of data and clear the remaining buffers.

[0017] According to a third aspect, an electronic device is provided, comprising: a processor and a memory configured to store a computer program that can be run on the processor, wherein the processor is configured to execute the steps of the method of the first aspect when running the computer program.

[0018] According to a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, wherein the computer program implements the steps of the method according to the first aspect when executed by a processor.

[0019] According to a fifth aspect, a computer program product is provided, comprising a computer program, wherein the computer program implements the steps of the method according to the first aspect when executed by a processor.

[0020] The present application provides a method, device and equipment for processing the switching between the foreground and background of an application. The method includes: in the case of detecting a cold start operation of a first application, controlling a window management service to request a graphics synthesis module to create a first layer for the first application; controlling the window management service to set the first layer to a display state; controlling the first application to request M buffers from an operating system, the buffers being used to cache frame data used by the graphics synthesis module for graphics synthesis; M being an integer greater than or equal to 2; in the case of detecting that the first application switches from the foreground to the background, controlling the window management service to set the first layer to a hidden state; controlling the first application to retain the buffer that caches the last frame of data, and clearing the remaining buffers. Based on this, when the first application switches to the foreground again, that is, hot starts, the graphics synthesis module does not need to create the first layer again, the window management service directly sets the first layer to a display state, and the graphics synthesis module can use the first layer to display the last frame of data, thereby shortening the time consumed by recreating the layer and shortening the time consumed by regenerating the last frame of data, thereby effectively shortening the time consumed by the frequent switching between the foreground and background of the first application. In addition, controlling the first application to clear the remaining buffers can release the memory space occupied by the buffers, thereby avoiding resource waste. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 1 ;

[0022] Figure 2 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 2 ;

[0023] Figure 3 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 3 ;

[0024] Figure 4 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 4 ;

[0025] Figure 5 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 5 ;

[0026] Figure 6 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 6 ;

[0027] Figure 7 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 7 ;

[0028] Figure 8 This is a schematic diagram of the cold start process of a desktop application in an embodiment of the present application;

[0029] Fig. 9 This is a schematic diagram of the process of switching from the foreground to the background and starting the chat application in the embodiment of the present application;

[0030] Fig.10 This is a flow chart of switching the desktop application from the background to the foreground and the chat application from the foreground to the background in the embodiment of the present application;

[0031] Fig.11 A schematic diagram of the structure of the foreground and background switching processing device used in the embodiment of the present application;

[0032] Fig.12 It is a schematic diagram of the structure of the electronic device in the embodiment of the present application. DETAILED DESCRIPTION

[0033] In order to enable a more detailed understanding of the features and technical contents of the embodiments of the present application, the implementation of the embodiments of the present application is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present application.

[0034] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing this embodiment and are not intended to limit this application.

[0035] In the following description, references to “some embodiments,” “this embodiment,” “this embodiment,” and examples, etc., describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.

[0036] If similar descriptions of "first / second" appear in the application documents, the following instructions are added. In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the present embodiment described here can be implemented in an order other than that illustrated or described here.

[0037] In this embodiment, the term "and / or" is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, object A and / or object B may represent three situations: object A exists alone, object A and object B exist at the same time, and object B exists alone.

[0038] The present application embodiment provides a method for processing foreground and background switching of an application. Figure 1 The process diagram of the foreground and background switching processing method used in the embodiment of the present application is as follows Figure 1 , applied to electronic devices, which can be smart phones, tablets and other devices. Figure 1 As shown, the foreground and background switching processing method of the application includes the following steps S101 to S105:

[0039] Step S101: when a cold start operation of a first application is detected, the window management service is controlled to request a graphics composition module to create a first layer for the first application.

[0040] In the embodiment of the present application, the cold start of an application refers to the process of an application being reopened by a user from a completely non-running state.

[0041] In the embodiment of the present application, the first application sends a cold start request to the window management service. When the window management service detects the cold start request (or cold start operation) of the first application, the window management server sends a request to create a layer of the first application to the graphics synthesis module (i.e., SurfaceFlinger). The graphics synthesis module creates a first layer (i.e., Surface) for the first application. The number of the first layer is at least one, and the first layer includes but is not limited to the application layer, the navigation bar layer, and the status bar layer.

[0042] Step S102: Control the window management service to set the first layer to a display state.

[0043] In an embodiment of the present application, when the window management service receives the layer creation completion signal sent by the graphics synthesis module, the window management service sets the first layer to a display state, so that the graphics synthesis module can display the corresponding frame data on the first layer.

[0044] Step S103: Control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module for performing graphics synthesis; M is an integer greater than or equal to 2.

[0045] In the embodiment of the present application, the first application sends a request for M buffers to the operating system, and the operating system allocates address information of M buffers to the first application. Subsequently, the first application caches the frame data processed by the graphics processing unit (GPU) in the corresponding free buffer. Then, based on the address information of the buffer, the first application obtains the next frame data in the buffer and sends it to the graphics synthesis module. The graphics synthesis module performs graphics synthesis processing on the frame data and then sends it to the display unit to be displayed on the first layer of the first application.

[0046] Exemplarily, if M is 2, that is, the first buffer and the second buffer, the first buffer is used to cache the first frame data, and the second buffer is used to cache the second frame data. After the graphics synthesis module processes the first frame data in the first buffer, the first buffer is idle, and the first buffer is used to cache the third frame data. After the graphics synthesis module processes the second frame data in the second buffer, the second buffer is idle, and the second buffer is used to cache the fourth frame data, and so on. It is not repeated here.

[0047] Step S104: when it is detected that the first application switches from the foreground to the background, the window management service is controlled to set the first layer to a hidden state.

[0048] In an embodiment of the present application, the first application sends a background switching request to the window management service. When the window management service detects that the first application needs to be switched from the foreground to the background, the first layer is set to a hidden state, so that the graphics synthesis module cannot use the first layer to display frame data.

[0049] It should be noted that when the first application is switched from the foreground to the background, the first layer is set to a hidden state, that is, the first layer is not cleared. Furthermore, when the first application is switched to the foreground again, i.e., hot-started, the graphics synthesis module does not need to re-create the first layer. The window management service directly sets the first layer to a display state. The graphics synthesis module can use the first layer to display frame data, thereby shortening the time consumed by recreating the layer.

[0050] Step S105: Control the first application to retain the buffer that caches the last frame of data, and clear the remaining buffers.

[0051] In an embodiment of the present application, when the first application switches from the foreground to the background, one of the M buffers caches the last frame of data, and the remaining buffers are idle. The first application retains the buffer that caches the last frame of data and clears the remaining buffers. Clearing the buffers can release the occupied memory space, thereby avoiding waste of resources.

[0052] It should be noted that when the first application switches from the foreground to the background, the first application is controlled to retain the buffer that caches the last frame of data. Further, when the first application switches to the foreground again, i.e., hot-starts, the graphics synthesis module can directly use the first layer to display the last frame of data, thereby shortening the time consumed by regenerating the last frame of data. In addition, the first application is controlled to clear the remaining buffers, thereby releasing the memory space occupied by the buffers, thereby avoiding resource waste.

[0053] In some embodiments of the present application, the method further includes the following steps S201 to S203:

[0054] Step S201: When it is detected that the first application is switched from the background to the foreground, the window management service is controlled to set the first layer to a display state.

[0055] In an embodiment of the present application, the first application sends a request to switch to the foreground to the window management service. When the window management service detects that the first application needs to switch from the background to the foreground, it sets the created first layer to the display state. The subsequent graphics synthesis module can use the first layer to display frame data, thereby shortening the time consumed by recreating the layer.

[0056] Step S202: Control the first application to request N buffers from the operating system again; N=M-1.

[0057] In the embodiment of the present application, when the first application switches from the foreground to the background, the first application is controlled to retain the buffer that caches the last frame of data and clear the remaining buffers. Therefore, when the first application switches to the foreground again, it is necessary to request M-1, i.e., N, buffers from the operating system. The buffer requested again is used to cache the frame data used by the graphics synthesis module when performing graphics synthesis during the operation of the first application.

[0058] Step S203: Control the first application to call the graphics synthesis module to perform synthesis processing on the last frame of data, so that the graphics synthesis module displays the processed data on the first layer.

[0059] In the embodiment of the present application, when the first application is switched to the foreground, the last frame of data is first obtained based on the address information of the buffer in which the last frame of data is cached and sent to the graphics synthesis module, which performs graphics synthesis processing on the last frame of data and then sends it to the display unit to be displayed on the first layer of the first application, thereby shortening the time consumed by regenerating the last frame of data.

[0060] In some embodiments of the present application, the method further includes steps S301 to S302:

[0061] Step S301: When a cold start operation of the first application is detected, the first application is controlled to generate a first drawing instruction set based on the first interface layout and store it in a preset storage space, the first drawing instruction set is used as a drawing instruction set reused when generating the next frame data, and the drawing instruction set is used to generate frame data used by the graphics synthesis module for graphics synthesis.

[0062] In an embodiment of the present application, the first interface layout refers to the interface layout that the user sees for the first time after the first application is cold started. The interface layout is the arrangement and organization of various components in the user interface (such as text boxes, buttons, images, etc.) on the screen. The first application generates a first drawing instruction set based on the first interface layout, and the first application controls the GPU to process the collected data based on the first drawing instruction set to obtain the first frame data used by the graphics synthesis module for graphics synthesis. Then, the first application sends the first frame data to the graphics synthesis module for graphics synthesis processing, and the graphics synthesis module sends the processed data to the display unit to display it on the first layer.

[0063] It should be noted that before generating the next frame of data used by the graphics synthesis module for graphics synthesis, part or all of the drawing instruction sets stored in the preset storage space can be reused, and the remaining drawing instruction sets only need to be generated based on the interface layout of the next frame, so as to obtain the drawing instruction set corresponding to the next frame of data. And so on, no further elaboration is given.

[0064] Step S302: when it is detected that the first application is switched from the foreground to the background, retaining the drawing instruction set in the preset storage space.

[0065] In an embodiment of the present application, when the first application switches from the foreground to the background, the first application retains the drawing instruction set in the preset storage space, so that when the first application returns to the foreground again, part or all of the drawing instruction set in the preset storage space can be reused, that is, there is no need to regenerate (or construct) the drawing instruction set, thereby shortening the time consumed by regenerating (or constructing) the drawing instruction set.

[0066] In some embodiments of the present application, the method also includes: when it is detected that the first application switches from the background to the foreground and the last frame data of the first application when it was last in the foreground is updated, controlling the first application to generate a second drawing instruction set for generating the next frame data based on the second interface layout and the drawing instruction set in the preset storage space.

[0067] In an embodiment of the present application, when the first application is switched from the background to the foreground, i.e., hot-started, the first application obtains the last frame of data based on the address information of the buffer that caches the last frame of data and sends it to the graphics synthesis module. The graphics synthesis module performs graphics synthesis processing on the last frame of data, and the image synthesis module sends the processed data to the display unit to display it on the first layer. Next, when it is necessary to update the last frame of data of the first application on the first layer when it was last in the foreground, part or all of the drawing instruction set stored in the preset storage space can be reused, and only the remaining drawing instruction set needs to be generated based on the second interface layout of the next frame, thereby obtaining the second drawing instruction set corresponding to the next frame of data. This shortens the time consumed by regenerating (or constructing) the drawing instruction set.

[0068] In some embodiments of the present application, steps S401 to S407 are also included:

[0069] Step S401: when a cold start operation of a first application is detected, the window management service is controlled to create a first window for the first application and the first window is set to be visible.

[0070] In an embodiment of the present application, the first application sends a cold start request to the window management service. When the window management service detects the cold start request (or cold start operation) of the first application, the window management service creates a first window for the first application and sets the first window to a visible state.

[0071] Step S402: Control the window management service to request the graphics synthesis module to create a first layer for the first window of the first application.

[0072] In an embodiment of the present application, the window management service sends a request to create a layer of the first application to the graphics synthesis module (ie, SurfaceFlinger), and the graphics synthesis module creates a first layer (ie, Surface) for the first application.

[0073] Step S403: Control the window management service to set the first layer to a display state.

[0074] In an embodiment of the present application, when the window management service receives the layer creation completion signal sent by the graphics synthesis module, the window management service sets the first layer to a display state, so that the graphics synthesis module can display the corresponding frame data on the first layer.

[0075] Step S404: Control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module for performing graphics synthesis; M is an integer greater than or equal to 2.

[0076] In the embodiment of the present application, the first application sends a request for M buffers to the operating system, and the operating system allocates address information of M buffers to the first application. Subsequently, the first application caches the frame data processed by the graphics processing unit (GPU) in the corresponding free buffer. Then, based on the address information of the buffer, the first application obtains the next frame data in the buffer and sends it to the graphics synthesis module. The graphics synthesis module performs graphics synthesis processing on the frame data and then sends it to the display unit to be displayed on the first layer of the first application.

[0077] Exemplarily, if M is 2, that is, the first buffer and the second buffer, the first buffer is used to cache the first frame data, and the second buffer is used to cache the second frame data. After the graphics synthesis module processes the first frame data in the first buffer, the first buffer is idle, and the first buffer is used to cache the third frame data. After the graphics synthesis module processes the second frame data in the second buffer, the second buffer is idle, and the second buffer is used to cache the fourth frame data, and so on. It is not repeated here.

[0078] Step S405: When it is detected that the first application switches from the foreground to the background, the window management service is controlled to set the first layer to a hidden state.

[0079] In an embodiment of the present application, the first application sends a background switching request to the window management service. When the window management service detects that the first application needs to be switched from the foreground to the background, the first layer is set to a hidden state, so that the graphics synthesis module cannot use the first layer to display frame data.

[0080] It should be noted that when the first application is switched from the foreground to the background, the first layer is set to a hidden state, that is, the first layer is not cleared. Furthermore, when the first application is switched to the foreground again, i.e., hot-started, the graphics synthesis module does not need to re-create the first layer. The window management service directly sets the first layer to a display state. The graphics synthesis module can use the first layer to display frame data, thereby shortening the time consumed by recreating the layer.

[0081] Step S406: Control the first application to request the window management service to set the first window to an invisible state.

[0082] In an embodiment of the present application, the first application sends a request to the window management service to set the first window to an invisible state, and the window management service sets the first window to an invisible state, that is, hides the first window of the first application.

[0083] Step S407: Control the first application to retain the buffer that caches the last frame of data, and clear the remaining buffers.

[0084] In an embodiment of the present application, when the first application switches from the foreground to the background, one of the M buffers caches the last frame of data, and the remaining buffers are idle. The first application retains the buffer that caches the last frame of data and clears the remaining buffers. Clearing the buffers can release the occupied memory space, thereby avoiding waste of resources.

[0085] It should be noted that when the first application switches from the foreground to the background, the first application is controlled to retain the buffer that caches the last frame of data. Further, when the first application switches to the foreground again, i.e., hot-starts, the graphics synthesis module can directly use the first layer to display the last frame of data, thereby shortening the time consumed by regenerating the last frame of data. In addition, the first application is controlled to clear the remaining buffers, thereby releasing the memory space occupied by the buffers, thereby avoiding resource waste.

[0086] In some embodiments of the present application, steps S501 to S504 are also included:

[0087] Step S501: when it is detected that the first application is switched from the background to the foreground, the window management service is controlled to set the first layer to the display state.

[0088] In an embodiment of the present application, the first application sends a request to switch to the foreground to the window management service. When the window management service detects that the first application needs to switch from the background to the foreground, it sets the created first layer to the display state. The subsequent graphics synthesis module can use the first layer to display frame data, thereby shortening the time consumed by recreating the layer.

[0089] Step S502: Control the first application to request the window management service to set the first window to a visible state.

[0090] In an embodiment of the present application, the first application sends a request to the window management service to set the first window to a visible state, and the window management service sets the first window to a visible state, that is, displays the first window of the first application.

[0091] Step S503: Control the first application to request N buffers from the operating system again; N=M-1.

[0092] In the embodiment of the present application, when the first application switches from the foreground to the background, the first application is controlled to retain the buffer that caches the last frame of data and clear the remaining buffers. Therefore, when the first application switches to the foreground again, it is necessary to request M-1, i.e., N, buffers from the operating system. The buffer requested again is used to cache the frame data used by the graphics synthesis module when performing graphics synthesis during the operation of the first application.

[0093] Step S504: Control the first application to call the graphics synthesis module to perform synthesis processing on the last frame of data, so that the graphics synthesis module displays the processed data on the first layer.

[0094] In the embodiment of the present application, when the first application is switched to the foreground, the last frame of data is first obtained based on the address information of the buffer in which the last frame of data is cached and sent to the graphics synthesis module, which performs graphics synthesis processing on the last frame of data and then sends it to the display unit to be displayed on the first layer of the first application, thereby shortening the time consumed by regenerating the last frame of data.

[0095] In some embodiments of the present application, the method further includes the following steps S601 to S602:

[0096] Step S601: When it is detected that the first application switches from the foreground to the background and the second application switches to the foreground, the window management service is controlled to set the second layer of the second application to a display state.

[0097] Step S602: Execute a startup animation operation of the second application.

[0098] In the embodiment of the present application, when the second application switches to the foreground, it can be switched to the foreground for the first time, that is, a cold start, or it can be switched to the foreground again, that is, a hot start.

[0099] In the embodiment of the present application, if the second application is switched to the foreground for the first time, i.e., cold start, the control window management service creates a second window for the second application and sets the second window to a visible state, and the control window management service requests the graphics synthesis module to create a second layer for the second window, and the control window management service sets the second layer of the second application to a display state. If the second application is switched to the foreground again, i.e., hot start, the second layer exists at this time, and it only needs to be set to a display state.

[0100] In the embodiment of the present application, the startup animation operation refers to a series of animation effects displayed when the second application is started.

[0101] In some embodiments of the present application, the method further includes the following steps S701 to S702:

[0102] Step S701: When it is detected that the first application switches from the background to the foreground and the second application switches from the foreground to the background, an exit animation operation of the second application is executed.

[0103] Step S702: When it is detected that the exit animation operation is finished, the window management service is controlled to set the layer of the second application to a hidden state.

[0104] In the embodiment of the present application, the exit animation operation refers to a series of animation effects displayed when the second application switches to the background. After the second application exit animation operation is completed, the layer of the second application is set to a hidden state.

[0105] Based on the above embodiments, this application takes the first application as a desktop application and the second application as a chat application as an example, and specifically describes the foreground and background switching processing method of the application as follows.

[0106] Figure 8 Schematic diagram of the cold start process of the desktop application in the embodiment of the present application. Figure 8 As shown, the following steps are included:

[0107] Step S801: The desktop application sends a cold start request to the window management service.

[0108] Step S802: The desktop application requests M buffers from the operating system.

[0109] The buffer is used to cache the frame data used by SurfaceFlinger for graphics synthesis; M is an integer greater than or equal to 2.

[0110] Step S803: The desktop application generates a first drawing instruction set based on the first interface layout and stores the first drawing instruction set in a preset storage space.

[0111] Step S804: The window management service creates a first window for the desktop application and sets the first window to be visible.

[0112] Step S805: The window management service sends a layer creation request for the desktop application to SurfaceFlinger.

[0113] Step S806: SurfaceFlinger creates a first layer for the desktop application.

[0114] Step S807: The window management service sets the first layer to a display state.

[0115] Fig. 9 The schematic diagram of the process of switching the desktop application from the foreground to the background and the chat application startup in the embodiment of the present application is as follows: Fig. 9 As shown, the following steps are included:

[0116] Step S901: The desktop application sends a chat application startup request to the window management service.

[0117] When you click on the chat application on the desktop application, the desktop application sends a request to start the chat application to the window management service.

[0118] Step S902: the window management service executes the operation of starting the chat application and notifies the chat application to start.

[0119] If the chat application is cold started, the window management service performs the operation of starting the chat application, that is, creating a second window for the chat application, setting the second window to be visible, and setting the window of the desktop application to be invisible. If the chat application switches to the foreground again, the window management service directly sets the second window to be visible, and sets the window of the desktop application to be invisible.

[0120] Step S903: The chat application initializes interface drawing.

[0121] After the chat application is launched, after one frame of drawing is completed, the window management service will be notified that one frame of drawing has been completed.

[0122] Step S904: The window management service sets the second layer of the chat application to a display state.

[0123] If the chat application is cold started, the window management service requests the graphics synthesis module to create a second layer for the second window of the chat application, and then the window management service sets the second layer of the chat application to be displayed. If the chat application is switched to the foreground again, the second layer exists, and the window management service directly sets the second layer of the chat application to be displayed.

[0124] Step S905: The desktop application executes the startup animation operation of the chat application.

[0125] The window management service notifies the desktop application to execute the startup animation operation of the chat application.

[0126] Step S906: The desktop application startup animation ends.

[0127] After the desktop application completes the chat application startup animation, it notifies the window management service.

[0128] Step S907: The window management service sets the first layer of the desktop application to a hidden state.

[0129] When the window management service detects that the chat application's window completely blocks the first window of the desktop application, it hides the first layer of the desktop application and notifies the desktop to hide.

[0130] Step S908: Notify the desktop to hide.

[0131] Step S909: The desktop application retains the buffer that caches the last frame of data, clears the remaining buffers, and retains the drawing instruction set in the preset storage space.

[0132] Fig.10 Schematic diagram of the process of switching the desktop application from the background to the foreground and the chat application from the foreground to the background in the embodiment of the present application. Fig.10 As shown, the following steps are included:

[0133] Step S1001: The chat application sends a background switching request to the window management service.

[0134] After using the chat application, the user triggers the operation of exiting the chat application and returning to the desktop application.

[0135] Step S1002: The window management service receives a background switching request from the chat application.

[0136] Step S1003: The window management service notifies the desktop application to display.

[0137] The window management service sets the first window of the desktop application to be visible.

[0138] Step S1004: the desktop application requests N buffers from the operating system again.

[0139] The desktop application then requests N buffers from the operating system, so that together with the buffer that previously cached the last frame of data, there are M buffers, which complete the number of frame data buffers.

[0140] Subsequently, the desktop application obtains the last frame of data retained when the desktop application was last switched to the background, sends it to SurfaceFlinger for graphics synthesis processing, and then displays it on the first layer through the display unit. To update the last frame of data when the desktop application was last switched to the background, the desktop application reuses part or all of the drawing instruction sets in the preset storage space, and then generates the remaining drawing instruction sets based on the second interface layout of the next frame, thereby obtaining a second drawing instruction set for generating the next frame of data.

[0141] Step S1005: The window management service sets the first layer of the desktop application to a display state.

[0142] Step S1006: The desktop application executes the exit animation operation of the chat application.

[0143] After the window management service side displays the first layer of the desktop application, it notifies the desktop application to execute the exit animation operation of the chat application.

[0144] Step S1007: The desktop application executes the exit animation operation and ends.

[0145] After the desktop application finishes executing the animation, the notification window management service can hide the second layer of the chat application.

[0146] Step S1008: The window management service sets the second layer of the chat application to a hidden state.

[0147] Based on this, we conclude:

[0148] 1) When the application exits the background, the application layer is not destroyed. During the next hot start, the window management service can display the application faster. There is no need to wait for the application layer to be recreated, the drawing instruction set to be built, and a frame of drawing to be completed before the window management service is notified to display the application.

[0149] 2) When the application exits the background, all drawing instructions are retained, and the previous drawing instructions can be reused when waiting for the next hot start.

[0150] 3) When the application exits the background, release the last frame data buffer sent to the SurfaceFlinger. Reduce the memory usage when exiting the background. Wait until the next time the application returns to the foreground, and then apply for a new frame data buffer to complete the number of frame data buffers.

[0151] When the application is hot-started, there is no need to wait for the application to complete a frame before starting the animation, no need to re-create the application's layers, and no need to rebuild the drawing instruction set of the application interface, thereby improving the startup speed of the application. The more complex the application interface, the more obvious the improvement effect. On some devices, the response delay of returning to the Launcher operation can be reduced by 25%.

[0152] To implement the method of the embodiment of the present application, based on the same inventive concept, the embodiment of the present application also provides a foreground and background switching processing device for an application, Fig.11 Schematic diagram of the structure of the foreground and background switching processing device used in the embodiment of the present application. Fig.11 As shown, the foreground and background switching processing device 110 of the application includes:

[0153] The control unit 1101 is configured to control the window management service to request the graphics synthesis module to create a first layer for the first application when a cold start operation of the first application is detected;

[0154] The control unit 1101 is further used to control the window management service to set the first layer to a display state;

[0155] The control unit 1101 is further used to control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module when performing graphics synthesis; M is an integer greater than or equal to 2;

[0156] The control unit 1101 is further configured to control the window management service to set the first layer to a hidden state when detecting that the first application switches from the foreground to the background;

[0157] The control unit 1101 is further configured to control the first application to retain the buffer that caches the last frame of data, and clear the remaining buffers.

[0158] In the embodiment of the present application, when the first application is switched to the foreground again, that is, hot-started, the graphics synthesis module does not need to re-create the first layer, and the window management service directly sets the first layer to the display state, and the graphics synthesis module can use the first layer to display the last frame of data, thereby shortening the time consumed by re-creating the layer and shortening the time consumed by regenerating the last frame of data. In addition, controlling the first application to clear the remaining buffers can release the memory space occupied by the buffers, thereby avoiding resource waste.

[0159] In some embodiments of the present application, the control unit 1101 is also used to control the window management service to set the first layer to a display state when it is detected that the first application switches from the background to the foreground; control the first application to request N buffers from the operating system again; N=M-1; control the first application to call the graphics synthesis module to perform synthesis processing on the last frame of data, so that the graphics synthesis module displays the processed data on the first layer.

[0160] In some embodiments of the present application, the control unit 1101 is also used to control the first application to generate a first drawing instruction set based on the first interface layout and store it in a preset storage space when a cold start operation of the first application is detected, and the first drawing instruction set is used as a drawing instruction set reused when generating the next frame data, and the drawing instruction set is used to generate frame data used by the graphics synthesis module when performing graphics synthesis; when it is detected that the first application switches from the foreground to the background, the drawing instruction set in the preset storage space is retained.

[0161] In some embodiments of the present application, the control unit 1101 is also used to control the first application to generate a second drawing instruction set for generating a next frame of data based on the second interface layout and the drawing instruction set in the preset storage space when it is detected that the first application switches from the background to the foreground and updates the last frame data of the first application when it was last in the foreground.

[0162] In some embodiments of the present application, the control unit 1101 is also used to control the window management service to create a first window for the first application and set the first window to a visible state; control the window management service to request the graphics synthesis module to create the first layer for the first window of the first application; control the first application to request the window management service to set the first window to an invisible state.

[0163] In some embodiments of the present application, the control unit 1101 is further used to control the first application to request the window management service to set the first window to a visible state when it is detected that the first application switches from the background to the foreground.

[0164] In some embodiments of the present application, the control unit 1101 is also used to control the window management service to set the second layer of the second application to a display state when it is detected that the first application switches from the foreground to the background and the second application switches to the foreground; and control the first application to execute the startup animation operation of the second application.

[0165] In some embodiments of the present application, the control unit 1101 is also used to control the first application to execute the exit animation operation of the second application when it is detected that the first application switches from the background to the foreground and the second application switches from the foreground to the background; and control the window management service to set the layer of the second application to a hidden state when it is detected that the exit animation operation ends.

[0166] The present application also provides another electronic device, Fig.12 Schematic diagram of the structure of the electronic device in the embodiment of the present application. Fig.12As shown, the electronic device 120 includes: a processor 1201 and a memory 1202 configured to store a computer program that can be run on the processor;

[0167] The processor 1201 is configured to execute the method steps in the aforementioned embodiment when running a computer program.

[0168] Of course, in practical applications, Fig.12 As shown, the components in the electronic device 120 are coupled together via a bus system 1203. It is understood that the bus system 1203 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 1203 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Fig.12 Various buses are labeled as bus system 1203.

[0169] In practical applications, the processor may be at least one of an application-specific integrated circuit (ASIC), a digital signal processing device (DSPD), a programmable logic device (PLD), a field-programmable gate array (FPGA), a controller, a microcontroller, and a microprocessor. It is understandable that for different devices, the electronic device used to implement the functions of the processor may also be other, and the embodiments of the present application do not specifically limit this.

[0170] The above-mentioned memory can be a volatile memory (volatile memory), such as a random access memory (RAM); or a non-volatile memory (non-volatile memory), such as a read-only memory (ROM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD); or a combination of the above-mentioned types of memory, and provide instructions and data to the processor.

[0171] In an exemplary embodiment, the present application also provides a computer-readable storage medium for storing a computer program.

[0172] Optionally, the computer-readable storage medium can be applied to any one of the methods in the embodiments of the present application, and the computer program enables the computer to execute the corresponding processes implemented by the processor in each method in the embodiments of the present application. For the sake of brevity, they are not repeated here.

[0173] Illustratively, an embodiment of the present application further provides a computer program product, including a computer program, which can be executed by a processor of an electronic device to complete the steps of any of the aforementioned methods.

[0174] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0175] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0176] In addition, all functional units in the embodiments of the present invention may be integrated into one processing module, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units. A person of ordinary skill in the art may understand that all or part of the steps of implementing the above method embodiments may be completed by hardware related to program instructions, and the above program may be stored in a computer-readable storage medium, which, when executed, executes the steps of the above method embodiments; and the above storage medium includes various media that can store program codes, such as mobile storage devices, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.

[0177] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0178] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0179] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.

[0180] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A method for processing foreground and background switching of an application, characterized in that: The method comprises: When a cold start operation of the first application is detected, controlling the window management service to request the graphics composition module to create a first layer for the first application; Controlling the window management service to set the first layer to a display state; Control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module when performing graphics synthesis; M is an integer greater than or equal to 2; When detecting that the first application switches from the foreground to the background, controlling the window management service to set the first layer to a hidden state; The first application is controlled to retain the buffer that caches the last frame of data and clear the remaining buffers.

2. The method according to claim 1, characterized in that The method further comprises: When detecting that the first application switches from the background to the foreground, controlling the window management service to set the first layer to a display state; Control the first application to request N buffers from the operating system again; N=M-1; The first application is controlled to call the graphics synthesis module to perform synthesis processing on the last frame of data, so that the graphics synthesis module displays the processed data on the first layer.

3. The method according to claim 1, characterized in that The method further comprises: When a cold start operation of the first application is detected, controlling the first application to generate a first drawing instruction set based on the first interface layout and storing the first drawing instruction set in a preset storage space, wherein the first drawing instruction set is used as a drawing instruction set reused when generating next frame data, and the drawing instruction set is used to generate frame data used by the graphics synthesis module when performing graphics synthesis; When it is detected that the first application is switched from the foreground to the background, the drawing instruction set in the preset storage space is retained.

4. The method according to claim 3, characterized in that The method further comprises: When it is detected that the first application switches from the background to the foreground and updates the last frame data of the first application when it was last in the foreground, the first application is controlled to generate a second drawing instruction set for generating the next frame data based on the second interface layout and the drawing instruction set in the preset storage space.

5. The method according to claim 1, characterized in that: The controlling window management service requests the graphics synthesis module to create a first layer for the first application, including: Control the window management service to create a first window for the first application, and set the first window to be in a visible state; Controlling the window management service to request the graphics synthesis module to create the first layer for the first window of the first application; After controlling the window management service to set the first layer to a hidden state, the method further includes: The first application is controlled to request the window management service to set the first window to an invisible state.

6. The method according to claim 5, characterized in that The method further comprises: When it is detected that the first application is switched from the background to the foreground, the first application is controlled to request the window management service to set the first window to a visible state.

7. The method according to claim 1, characterized in that The method further comprises: When it is detected that the first application switches from the foreground to the background and the second application switches to the foreground, controlling the window management service to set the second layer of the second application to a display state; Execute a startup animation operation of the second application.

8. The method according to claim 7, characterized in that The method further comprises: When it is detected that the first application switches from the background to the foreground, and the second application switches from the foreground to the background, executing an exit animation operation of the second application; When it is detected that the exit animation operation ends, the window management service is controlled to set the layer of the second application to a hidden state.

9. A device for processing foreground and background switching of an application, characterized in that: The device comprises: A control unit, configured to control the window management service to request the graphics synthesis module to create a first layer for the first application when a cold start operation of the first application is detected; The control unit is further used to control the window management service to set the first layer to a display state; The control unit is further used to control the first application to request M buffers from the operating system, where the buffers are used to cache frame data used by the graphics synthesis module when performing graphics synthesis; M is an integer greater than or equal to 2; The control unit is further configured to control the window management service to set the first layer to a hidden state when detecting that the first application switches from the foreground to the background; The control unit is further used to control the first application to retain the buffer that caches the last frame of data and clear the remaining buffers.

10. An electronic device, characterized in that: The electronic device comprises: a processor and a memory configured to store a computer program capable of running on the processor, Wherein, the processor is configured to execute the steps of the method according to any one of claims 1 to 8 when running the computer program.