Interface switching method and electronic device
By intercepting the re-layout and destruction operations of desktop applications in electronic devices, maintaining the existence of the desktop root layout and layers solves the problem of slow response speed when returning to the desktop, and improves user experience and system performance.
Patent Information
- Application Number
- CN202311196490.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-15
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-09-15
AI Technical Summary
After the user triggers the return to the desktop operation, the electronic device responds slowly, resulting in a poor user experience.
By implementing the interface switching method in electronic devices, desktop applications are prevented from performing window re-layout operations when returning to the desktop, intercept the process of destroying desktop layers, and maintain the visibility of the desktop root layout and the existence of layers, so that they can be used directly when returning to the desktop. Undestroyed layers are displayed.
It improves the response speed of returning to the desktop, saves CPU resources and memory consumption, and improves the user experience.
Smart Images

Figure CN117289837B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of display technology, and in particular relates to an interface switching method and an electronic device. Background Art
[0002] As electronic devices become more and more intelligent, more and more application software is installed and run in electronic devices. During the interaction between a user and an electronic device, the electronic device can switch between the application interface of each application software and the desktop based on the user's operation. For example, a user can open the application software by clicking the icon of the application software on the desktop of the electronic device to display the interface provided by the application software. For another example, a user can return to the desktop by clicking the return to the main interface button in the three-button navigation on the electronic device.
[0003] When an electronic device returns to the desktop, the electronic device system needs to process the desktop interface. Therefore, after the user triggers the operation of returning to the desktop, the electronic device may delay for a period of time before displaying the desktop. Currently, the time from when the user triggers the operation of returning to the desktop to when the electronic device displays the desktop is long. From the user's perspective, the response speed of returning to the desktop is slow. Summary of the invention
[0004] The present application provides an interface switching method and an electronic device, which can improve the response speed of returning to the desktop.
[0005] In a first aspect, the present application provides an interface switching method, which is applied to an electronic device, and the method includes: the electronic device displays a desktop; in response to a user's input of a startup operation to a first application in the electronic device, the interface of the first application is displayed; wherein, after receiving the startup operation, the desktop application in the electronic device does not perform a window layout operation; in response to an input trigger operation to return to the desktop, the desktop is displayed; wherein, after receiving the trigger operation to return to the desktop, the desktop application does not perform a window layout operation, and the first application performs a window layout operation.
[0006] After receiving the start operation, the desktop application does not perform the window layout operation, which means that the desktop application does not perform the operation of destroying the desktop window. In this way, on the one hand, the desktop window can be intercepted and destroyed, and on the other hand, CPU resources can be released so that the CPU can speed up processing other processes.
[0007] After receiving the trigger operation to return to the desktop, the desktop application does not perform the window layout operation, which means that the desktop application does not perform the operation of creating a desktop window. In this way, the display can be based on the desktop layer that has not been destroyed, saving the time consumed in creating the desktop window, displaying the desktop faster, and improving the hand response performance of returning to the desktop.
[0008] In one implementable manner, after receiving the start operation, the method further includes: the desktop application executes an operation of stopping the active Activity; during the process of the desktop application executing the operation of stopping the Activity, if the desktop application determines that the target Activity to be stopped is a desktop Activity, the desktop application maintains the desktop root layout visible state as visible; wherein, if the desktop root layout visible state does not change, the desktop application does not perform a window re-layout operation.
[0009] In this way, when the desktop application is running in the foreground and the background, the desktop root layout visible state is visible. Since the desktop root layout visible state has not changed, after receiving the start operation, the desktop application will not be triggered to perform the window layout operation again.
[0010] In one implementable manner, after receiving the start operation, the method further includes: if the desktop application determines that the target stopped Activity is a desktop Activity, the desktop application sets the save window state to a save state; wherein, when the save window state is a save state, the desktop application does not destroy the desktop layer in the desktop application.
[0011] Thus, after receiving the start operation, the desktop application is intercepted from destroying the desktop layer by setting the save window state to the save state. Thus, after receiving the trigger operation to return to the desktop, the saved desktop layer can be directly used for display.
[0012] In one implementable manner, after receiving the start operation, the method further includes: after the desktop application completes the operation of stopping the Activity, the desktop application sends a notification of completion of stopping the Activity to the activity management service AMS in the electronic device; after the activity management service receives the notification of completion of stopping the Activity, if the activity management service determines that the target layer to be destroyed is the desktop layer, the activity management service sets the layer destruction status to not destroyed; wherein, when the layer destruction status is not destroyed, the activity management service does not destroy the desktop layer in the activity management service.
[0013] In this way, after receiving the start operation, the layer destruction state is set to not be destroyed, so as to intercept AMS from destroying the desktop layer.
[0014] In one implementable manner, after receiving a trigger operation to return to the desktop, the method further includes: the desktop application maintains the desktop root layout visibility state as visible; wherein, if the desktop root layout visibility state does not change, the desktop application does not perform a window re-layout operation; the first application sets the root layout visibility state of the first application to invisible; wherein, if the root layout visibility state of the first application changes, the first application performs a window re-layout operation.
[0015] Thus, for the desktop application, since the desktop root layout visible state is always visible, the desktop application will not be triggered to perform a window re-layout operation. For the first application, since the root layout visible state of the first application changes from visible to invisible, the first application will be triggered to perform a window re-layout operation.
[0016] In one implementable manner, displaying the desktop in response to an input trigger operation for returning to the desktop includes: obtaining a desktop layer from the memory of the electronic device in response to an input trigger operation for returning to the desktop; and displaying the desktop based on the desktop layer.
[0017] In this way, in response to the input trigger operation of returning to the desktop, the desktop application does not need to perform a window re-layout operation to obtain the desktop layer again. Instead, the desktop layer can be directly obtained from the memory of the electronic device, and the desktop can be displayed based on the desktop layer.
[0018] In one implementable manner, the memory of the electronic device includes desktop layer drawing data and desktop layer rendering data, and the method further includes: during the process of the desktop application executing the operation of stopping the Activity, if the desktop application determines that the target Activity to be stopped is a desktop Activity, then clearing the desktop layer rendering data in the memory of the electronic device.
[0019] In this way, since the rendering operation is performed based on the desktop layer drawing data, the time consumed to obtain the rendered desktop layer is very small. Therefore, the memory pressure can be relieved by clearing the desktop layer rendering data in the memory.
[0020] In one implementable manner, the displaying the desktop in response to an input triggering operation for returning to the desktop includes: obtaining the desktop layer drawing data in response to an input triggering operation for returning to the desktop; performing a rendering operation based on the desktop layer drawing data to obtain a rendered desktop layer; and displaying the desktop based on the rendered desktop layer.
[0021] In a second aspect, the present application provides an electronic device, comprising a memory and a processor; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code comprises computer instructions, and when the processor executes the computer instructions, the electronic device executes a method as described in any one of the first aspects.
[0022] In a third aspect, the present application provides a computer-readable storage medium, characterized in that a computer program or instructions are stored in the computer-readable storage medium, and when the computer program or instructions are executed, the method described in any one of the first aspects is executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1 A schematic diagram of a user interface of an electronic device provided in an embodiment of the present application;
[0025] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0026] Figure 3 A schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;
[0027] Figure 4 A schematic diagram of a workflow of an interface switching method provided in an embodiment of the present application;
[0028] Figure 5 A schematic diagram of a workflow of a method for intercepting a desktop application from destroying a desktop layer provided in an embodiment of the present invention;
[0029] Figure 6 A schematic diagram of a workflow of a method for intercepting AMS from destroying a desktop layer provided in this embodiment;
[0030] Fig. 7A A schematic diagram of a workflow of a method for updating the visible state of a desktop root layout provided in the present embodiment;
[0031] Figure 7B A schematic diagram of a workflow of a method for intercepting and destroying a desktop window provided in an embodiment of the present invention;
[0032] Figure 8A schematic diagram of a workflow of another interface switching method provided in an embodiment of the present application;
[0033] Fig. 9 A schematic diagram of a workflow of a method for cleaning desktop layer rendering data provided in an embodiment of the present application;
[0034] Fig.10 A schematic diagram of the workflow of another interface switching method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] To facilitate the understanding of the technical solution of the application, some concepts involved in the application are first explained below.
[0036] Desktop application, used to manage desktops, for example, starting or stopping desktops.
[0037] Activity manager service (AMS) is used to manage the life cycle of the application's activities. Taking some states in the life cycle as an example, when an application is started, the activity corresponding to the application is first in the on create state; when the application switches from the foreground to the background, the activity enters the on stop state.
[0038] Window manager service (WMS) is used to create windows.
[0039] Among them, desktop applications and other applications in electronic devices except desktop applications belong to application-side processes, and AMS and WMS belong to system server-side processes. Therefore, the communication between the desktop application and AMS, and the communication between the desktop application and WMS belong to cross-process communication. In some embodiments, the desktop application and AMS can communicate asynchronously through binder, and the desktop application and WMS can also communicate asynchronously through binder.
[0040] like Figure 1 As shown in (a) and (b) in the figure, the desktop of the electronic device displays icons of multiple applications, such as video applications, camera applications, setting applications, etc. When using an electronic device, the user can start the corresponding application by clicking the application icon on the desktop of the electronic device. Taking the start of the video application as an example, after starting the video application, the display interface of the electronic device switches from the desktop to the video application interface. Correspondingly, the video application runs in the foreground, and the desktop application retreats to the background.
[0041] When the desktop switches from the foreground to the background, the video application executes the process of drawing the video application interface, and the desktop application executes the process of destroying the desktop. The process of destroying the desktop mainly includes the process of destroying the desktop window (Window) and destroying the desktop layer (Surface).
[0042] Among them, the window can be understood as the carrier of the layer, and the layer refers to the content displayed in the window. The layer includes the rendered content that can be sent to the display screen for display. For example, a desktop window may include one or more desktop layers, and each desktop layer may include interface elements, interface layout, size, display position, etc.
[0043] like Figure 1 As shown in (c) and (d) in the figure, when the desktop is running in the background, the user can trigger the desktop to switch from the background to the foreground through various gesture information, so that the electronic device displays the desktop.
[0044] Exemplarily, the user can trigger the electronic device to enter multitasking or return to the desktop through gesture navigation (for example, the user's finger slides upward from the bottom of the display screen of the electronic device); or, the user can trigger the electronic device to return to the desktop through floating navigation (for example, the user's finger clicks on the floating ball button displayed on the display screen of the electronic device); or, the user can trigger the electronic device to enter multitasking or return to the desktop through three-button navigation (for example, the user's finger clicks on the return to main interface button in the three-button navigation).
[0045] When the desktop switches to the foreground, the visibility of the desktop root layout changes from invisible to visible. In this way, in response to the change in the visibility of the desktop root layout, the desktop application is triggered to perform a window re-layout operation (called relayoutWindow) to obtain a desktop window. Then, based on the desktop window obtained by the window re-layout operation, further drawing and rendering operations are performed to obtain a desktop layer. Finally, the desktop layer is sent to the display screen for display.
[0046] It can be seen that the relayoutWindow operation is the main process in the process of switching the desktop to the foreground. In the process of switching the desktop to the foreground, relayoutWindow is mainly used to create a desktop window for the drawing process and the rendering process to draw and render to obtain the desktop layer.
[0047] However, when the electronic device is under high load (for example, multiple application processes are running in the background of the electronic device), the desktop application process may not be scheduled for a long time, resulting in a slow progress and long time for the desktop application to execute relayoutWindow. In this way, after the user inputs the trigger operation to return to the desktop, it takes a long time for the desktop to be displayed on the electronic device, resulting in slow response to return to the desktop and affecting the user experience.
[0048] To solve the above problems, an embodiment of the present application provides an interface switching method, when the desktop is switched from the foreground to the background, the visible state of the desktop root layout is not modified, and the visible state of the desktop root layout is kept visible. In this way, when the desktop is switched back to the foreground, since the visible state of the desktop root layout is always visible, the visible state of the desktop root layout has not changed, and therefore, the desktop application will not be triggered to perform the relayoutWindow operation. In addition, when the desktop is switched from the foreground to the background, the method intercepts the process of destroying the desktop layer, so that the desktop layer is still retained when the desktop is switched to the background. In this way, when the desktop is switched back to the foreground, even if the desktop application does not perform the relayoutWindow operation, it can be displayed based on the undestroyed desktop layer. In this way, when the desktop is switched back to the foreground, since the desktop application does not perform the relayoutWindow operation, it is directly displayed based on the undestroyed desktop layer, so that the desktop can be displayed faster and the hand-following response performance of returning to the desktop can be improved.
[0049] The following describes the interface switching method provided in the embodiment of the present application.
[0050] The interface switching method provided in the embodiment of the present application can be applied to electronic devices. In some implementations, the electronic devices can be mobile phones, tablet computers, handheld computers, personal computers (PCs), personal digital assistants (PDAs), wearable devices and other electronic devices. The embodiment of the present application does not limit the specific form of the electronic device.
[0051] For example, taking the electronic device as a mobile phone, Figure 2 FIG. 1 is a schematic diagram showing the structure of an electronic device provided by an embodiment of the present application. Figure 2 As shown, 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, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0052] Among them, the above-mentioned sensor module 180 may include sensors such as a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L and a bone conduction sensor 180M.
[0053] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0054] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0055] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0056] A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or circulated. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system. In some embodiments, the processor 110 may include one or more interfaces.
[0057] It is understandable that the interface connection relationship between the modules shown in this embodiment is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0058] The charging management module 140 is used to receive charging input from a charger. The charger can be a wireless charger or a wired charger. While the charging management module 140 charges the battery 142, it can also power the electronic device through the power management module 141.
[0059] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160.
[0060] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0061] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0062] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1.
[0063] The wireless communication module 160 can provide wireless communication solutions for application in the electronic device 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc.
[0064] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, so that electronic device 100 can communicate with the network and other devices through wireless communication technology.
[0065] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0066] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. For example, the display screen 194 can be a touch screen.
[0067] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0068] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0069] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc.
[0070] The electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor, etc. For example, the user's voice information can be collected through the microphone 170C, and the feedback result of the user's voice information can be played through the speaker 170A.
[0071] The touch sensor is also called a "touch panel". The touch sensor can be arranged on the display screen 194, and the touch sensor and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor is used to detect touch operations acting on or near it. The touch sensor can pass 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 the display screen 194. In other embodiments, the touch sensor can also be arranged on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0072] In the embodiment of the present application, the electronic device 100 can detect the touch operation input by the user on the touch screen through the touch sensor, and collect one or more of the touch position of the touch operation on the touch screen, the touch time, etc. In some embodiments, the electronic device 100 can determine the touch position of the touch operation on the touch screen by combining the touch sensor 180K and the pressure sensor 180A.
[0073] The button 190 includes a power button, a volume button, etc. The button 190 may be a mechanical button or a touch button. The electronic device 100 may receive a button input and generate a key signal input related to the user settings and function control of the electronic device 100. For example, the voice interaction function may be awakened by long pressing the power button.
[0074] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0075] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, message, missed call, notification, etc. The SIM card interface 195 is used to connect the SIM card. The SIM card may be connected to or disconnected from the electronic device 100 by inserting the SIM card interface 195 or pulling the SIM card interface 195 out. The electronic device 100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 may support Nano SIM card, Micro SIM card, SIM card, etc.
[0076] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the Android system of the layered architecture is taken as an example to exemplify the software structure of the electronic device 100.
[0077] Figure 3 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0078] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.
[0079] The application layer can include a series of application packages.
[0080] like Figure 3 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, setting, application and other applications.
[0081] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0082] like Figure 3 As shown, the application framework layer may include activity management service, window management service, content provider, view system, phone manager, resource manager, notification manager, etc.
[0083] The window management service is used to manage window programs. The window management service can obtain the display size, determine whether there is a status bar, lock the screen, capture the screen, draw windows, etc.
[0084] The activity management service is used to manage the life cycle of the application's Activity.
[0085] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0086] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0087] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).
[0088] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0089] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0090] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0091] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.
[0092] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0093] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0094] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0095] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0096] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0097] A 2D graphics engine is a drawing engine for 2D drawings.
[0098] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0099] The interface switching method provided in the embodiment of the present application is described in detail below.
[0100] like Figure 4 As shown, the interface switching method provided in the embodiment of the present application may include the following steps:
[0101] S201: The desktop application receives an operation from a user to start a first application.
[0102] In the embodiment of the present application, the first application may be any application other than a desktop application.
[0103] The embodiment of the present application does not limit the method of starting the first application. Taking the first application as a video application as an example, the user can start the video application by clicking the icon of the video application on the desktop, so that the video application interface is displayed on the display interface of the electronic device. For another example, the user can also start the first application by voice input or the like.
[0104] In some embodiments, after the user clicks the icon of the video application on the desktop, the desktop application can first perceive the click event and can identify the application to be launched based on the click event, for example, identify the video application to be launched.
[0105] In response to receiving the user's operation of starting the first application, the first application is switched to the foreground and the desktop is switched to the background. Correspondingly, the Activity of the first application is started (i.e., StartActivity is executed), and the Activity of the desktop application is stopped (i.e., StopActivity is executed).
[0106] S202: The desktop application requests the AMS to start Activity 1, where Activity 1 is the Activity of the first application.
[0107] S203: After receiving the request to start Activity1, the AMS sends a notification of creating Activity1 to the first application.
[0108] S204, after receiving the notification of creating Activity1, the first application creates Activity1; and after creating Activity1, sends a notification of the completion of creating Activity1 to the AMS.
[0109] S205, after receiving the notification that Activity1 is created, the AMS sends a notification to play the animation effect to the desktop application.
[0110] S206, after receiving the notification to play the animation effect, the desktop application plays the animation effect; and after the animation effect is played, the desktop application sends a notification to the AMS to end the animation effect playing.
[0111] It should be noted that the embodiment of the present application is only exemplified by the case where the interface switching process includes transition effects. In some embodiments, if the interface switching process does not include transition effects, the above steps S205 to S206 may not be included. Correspondingly, after receiving the notification that Activity1 is created, AMS sends a notification to the desktop application to stop Activity2.
[0112] S207, after receiving the notification of the end of the animation playing, the AMS sends a notification to the desktop application to stop executing Activity2, where Activity2 is a desktop Activity.
[0113] S208, after receiving the notification to stop Activity2, the desktop application determines whether the target Activity to be stopped is an Activity of the desktop application.
[0114] Each Activity has attribute information, including the application package name, that is, the application name. For example, the application package name corresponding to Activity1 is the name of application A. The application package name corresponding to Activity2 is the desktop.
[0115] In this way, the desktop application can determine whether Activity2 is the Activity corresponding to the desktop application through the application package name of Activity2.
[0116] After the desktop application determines whether Activity2 is the activity corresponding to the desktop application, it mainly performs two tasks. The first part is to set the save window (preserveWindow) state, and the second part is to set the desktop root layout visible (DecorView Visibility) state.
[0117] For the method of setting the preserveWindow state, please refer to the description of steps S209-S211. For the method of setting the visible state of the desktop root layout, please refer to the description of steps S212-S213.
[0118] S209: If Activity2 is an Activity corresponding to a desktop application, the desktop application sets the preserveWindow state to a saved state. For example, the desktop application sets preserveWindow=true.
[0119] It should be noted here that if Activity2 is not the Activity corresponding to the desktop application (for example, the second application switches to the background running scenario), the second application keeps the preserveWindow state as unsaved (i.e. preserveWindow = false). That is to say, in the embodiment of the present application, preserveWindow is set to true only in the desktop switching to the background scenario.
[0120] S210, the desktop application determines whether the preserveWindow state is a saved state. For example, the desktop application determines whether preserveWindow is true.
[0121] S211, if the preserveWindow state is a non-saving state, the desktop application destroys the desktop layer.
[0122] If the status of preserveWindow is the saved status, the process of destroying the desktop layer ends and the process can return to step S208.
[0123] Since preserveWindow=true is set when Activity2 is the Activity corresponding to the desktop application, when the desktop switches to the background, the desktop application will not execute step S211, that is, the desktop layer will not be destroyed.
[0124] In this way, the embodiment of the present application identifies Activity2 as the activity corresponding to the desktop application, and sets preserveWindow to true when Activity2 is the activity corresponding to the desktop application, thereby intercepting the process of the desktop application destroying the desktop layer. In this way, even if the desktop application is switched to the background, the desktop application still retains the desktop layer.
[0125] S212: If Activity2 is an Activity corresponding to a desktop application, the desktop application keeps the desktop root layout visible.
[0126] When the desktop is running in the foreground, the visible state of the desktop root layout is visible. In the related art, when the desktop is switched to the background, the desktop state is set to invisible. In the present embodiment, when the desktop is switched to the background, the visible state of the desktop root layout is not modified, and the visible state of the desktop root layout is kept visible.
[0127] The change in the visible state of the desktop root layout is a condition that triggers the desktop application to perform the relayoutWindow operation. Specifically, if the visible state of the desktop root layout changes, the desktop application performs the relayoutWindow operation; if the visible state of the desktop root layout does not change, the desktop application does not perform the relayoutWindow operation.
[0128] Thus, in the embodiment of the present application, when the desktop is switched from the foreground to the background, the visible state of the desktop root layout is always visible, and the visible state of the desktop root layout has not changed. Thus, since the visible state of the desktop root layout has not changed, the desktop application will not be triggered to perform the relayoutWindow operation. Correspondingly, when the desktop is switched from the background to the foreground, the visible state of the desktop root layout is also always visible, and the visible state of the desktop root layout has not changed, thus, the desktop application will not be triggered to perform the relayoutWindow operation.
[0129] It should be noted here that relayoutWindow refers to the rearrangement of the window. When the desktop switches from the foreground to the background, the desktop application does not perform the relayoutWindow operation, which means that the desktop application does not perform the operation of destroying the desktop window. Correspondingly, the desktop application performs the relayoutWindow operation, which means that the desktop application performs the operation of destroying the desktop window. When the desktop switches from the background to the foreground, the desktop application does not perform the relayoutWindow operation, which means that the desktop application does not perform the operation of creating a desktop window.
[0130] It should also be noted that when the desktop switches from the foreground to the background, the desktop application does not perform the relayoutWindow operation (the operation of destroying the desktop window), but the first application performs the relayoutWindow operation, that is, the first application performs the operation of creating a window of the first application. Similarly, when the desktop switches from the background to the foreground, the desktop application does not perform the relayoutWindow operation (the operation of creating a desktop window), but the first application performs the relayoutWindow operation, that is, the first application performs the operation of destroying the window of the first application.
[0131] For the method of determining whether to trigger the desktop application to execute relayoutWindow based on the change in the visible state of the desktop root layout, please refer to the description of steps S218 to S221.
[0132] S213, after the desktop application completes stopping Activity2, it sends a notification of completion of stopping Activity2 to the AMS.
[0133] For example, the desktop application sends ActivityStopped to the AMS. Thus, after receiving ActivityStopped, the AMS determines that the desktop application has completed the operation of stopping Activity2.
[0134] After receiving the notification that Activity2 is stopped, AMS executes the process of intercepting the server to destroy the desktop layer. For details, please refer to the description of steps S214 to S217.
[0135] S214, after receiving the notification of completion of stopping Activity2, the AMS determines whether the target layer to be destroyed is the desktop layer.
[0136] S215: If the target layer to be destroyed is the desktop layer, the AMS sets the layer destroying (mDestroying) state to not destroying. For example, the AMS sets mDestroying = false.
[0137] It should be noted here that if the target layer to be destroyed is not the desktop layer (for example, when other applications are switched to the background), the mDestroying state of other applications is kept as destroyed (i.e., mDestroying = true). In other words, in the embodiment of the present application, the mDestroying state of the desktop application is set to false only in the scenario of switching from the desktop to the background.
[0138] S216, the AMS determines whether the mDestroying state is a destroying state. For example, the desktop application determines whether mDestroying is true.
[0139] S217, if the mDestroying state is destroyed, the AMS destroys the desktop layer. If the mDestroying state is not destroyed, the layer destruction process ends and the process returns to step S214.
[0140] Since mDestroying=false is set when the desktop is switched to the background, the AMS does not execute step S217, that is, the desktop layer is not destroyed.
[0141] In this way, the embodiment of the present application intercepts the process of AMS destroying the desktop layer by identifying whether the target layer to be destroyed is the desktop layer, and setting mDestroying to false when the target layer to be destroyed is the desktop layer. In this way, even if the desktop is switched to background operation, AMS still retains the desktop layer.
[0142] It should be noted that if only the desktop application is intercepted from destroying the desktop layer, and the AMS is not intercepted from destroying the desktop layer, when returning to the desktop and using the saved desktop layer for display, display errors may occur due to inconsistency between the desktop layer information on the application side and the server side. Therefore, the embodiment of the present application further intercepts the AMS from destroying the desktop layer to ensure that there will be no display errors when returning to the desktop.
[0143] S218, the AMS sends a notification of setting the visible status to the desktop application.
[0144] After AMS completes the process of intercepting the server destroying the desktop layer, AMS sends a notification to the desktop application to set the visible state. For example, AMS can call the desktop application to set the visible state through the function setClientVisible.
[0145] S219, after receiving the notification of setting the visible state, the desktop application determines whether the visible state of the desktop root layout has changed.
[0146] In some embodiments, the parameter DecorView VisibilityChanged may be used to indicate whether the state of DecorViewVisibility has changed, wherein DecorView VisibilityChanged=true indicates that the visible state of the root layout has changed; and DecorView VisibilityChanged=false indicates that the visible state of the root layout has not changed.
[0147] Among them, DecorView Visibility Changed is used to represent the change in the visible state of the root layout of the application when the application is running in the foreground and background.
[0148] For example, in the embodiment of the present application, when the desktop is running in the foreground, the desktop root layout visibility state is visible. When the desktop is running in the background, the desktop root layout visibility state is still visible. In this way, whether the desktop is switched to the foreground or the background, the desktop's DecorView Visibility Changed is always false.
[0149] For another example, when the first application is running in the foreground, the visible state of the root layout of the first application is visible. When the first application is running in the background, the visible state of the root layout of the first application is invisible. In this way, whether the first application is switched to the foreground or the background, the DecorView Visibility Changed of the first application is always true.
[0150] In some embodiments, the visible state of the root layout corresponding to the desktop when it is running in the foreground can be saved in ViewRootlmpl, and the visible state of the root layout corresponding to the desktop when it is running in the background can be saved in DecorView.
[0151] In this way, when judging whether the visible state of the desktop root layout has changed, the visible state of the desktop root layout can be obtained from ViewRootlmpl and DecorView respectively. Then, the two are compared to see whether they have changed. If it has changed, DecorView Visibility Changed = true; otherwise, DecorView Visibility Changed = false.
[0152] Exemplarily, if the desktop root layout visible state in ViewRootlmpl is true and the desktop root layout visible state in DecorView is false, then the desktop's DecorView Visibility Changed = true. If the desktop root layout visible state in ViewRootlmpl is true and the desktop root layout visible state in DecorView is true, then the desktop's DecorView Visibility Changed = false.
[0153] S220, if the visible state of the desktop root layout changes, the desktop application sends a notification to the WMS to execute the relayoutWindow operation. If the visible state of the desktop root layout does not change, the desktop application is not triggered to execute the relayoutWindow operation, and the process returns to step S218.
[0154] S221, after receiving the notification to execute the relayoutWindow operation, the WMS executes the relayoutWindow operation to destroy the desktop window.
[0155] Combining step S212 and steps S218-S221, it can be seen that since the desktop root layout visible state is kept visible in S212, the desktop root layout visible state is always visible and has not changed. In this way, in the scenario of desktop switching to background, steps S220-S221 will not be triggered, that is, the destruction of the desktop window can be intercepted.
[0156] In addition, in the desktop-to-background scenario, since the desktop application does not perform the relayoutWindow operation (the operation of destroying the desktop window), this can save CPU resources so that the CPU can speed up the processing of other processes.
[0157] In summary, the interface switching method provided by the embodiment of the present application, on the one hand, always keeps the visible state of the desktop root layout visible during the process of switching the desktop to the background, so that the desktop application will not be triggered to perform the relayoutWindow operation regardless of whether it is in the process of switching the desktop to the background or the process of switching the desktop to the foreground. On the other hand, since the desktop application and AMS are intercepted from destroying the desktop layer during the process of switching the desktop to the background. Therefore, when the desktop returns to the foreground, the desktop layer can be obtained even if the desktop application is not triggered to perform the relayoutWindow operation. In this way, when the desktop returns to the foreground, the undestroyed desktop layer can be directly loaded for display, and there is no need to perform the relayoutWindow operation through the desktop application to recreate the desktop window and the desktop layer, thereby improving the hand-following response speed of returning to the desktop.
[0158] Please continue to see Figure 4 , steps S207 to S211 are the process of intercepting the desktop application destroying the desktop layer, steps S214 to S217 are the process of intercepting the AMS destroying the desktop layer, steps S212 and steps S218-S221 are the process of updating the desktop root layout visibility, and intercepting the desktop application from executing the relayoutWindow operation based on the desktop root layout visibility change. The internal implementation processes of the above three parts are introduced below.
[0159] like Figure 5 As shown, the method of intercepting the desktop application from destroying the desktop layer can be implemented by calling multiple classes in the desktop application, such as StopActivityItem, ActivityThread, Activity, WindowMangerGlobal, ViewRootImpl, Surface, and SurfaceControl. For details, please refer to the following steps:
[0160] S301, StopActivityItem calls ActivityThread to stop the desktop Activity.
[0161] Among them, StopActivityItem can be created by ActivityRecord on the AMS side and passed to the desktop application through the binder to stop the Activity life cycle.
[0162] For example, StopActivityItem can call ActivityThread through the handleStopActivity function to stop the desktop Activity.
[0163] S302, ActivityThread internally stops the desktop Activity.
[0164] After ActivityThread receives the call of handleStopActivity function, it can call performStopActivityInner function to stop the desktop Activity internally.
[0165] S303, ActivityThread calls Activity to execute and stop the desktop Activity.
[0166] During the internal execution of stopping the desktop Activity, ActivityThread can call Activity through the performStop function to stop the desktop Activity.
[0167] S304, during the process of stopping the desktop Activity, the Activity determines whether the target Activity 2 to be stopped is an Activity of the desktop application.
[0168] In some embodiments, the function performStop may include the application package name of the target Activity2 to be stopped. For example, the application package name of Activity2 is the name of a desktop application. In this way, the Activity can determine whether the target Activity2 to be stopped is an Activity of a desktop application by using the application package name of Activity2 passed as a parameter.
[0169] S305: If Activity2 is an Activity of a desktop application, the Activity sets preserveWindow=true.
[0170] In this way, when the Activity executes performStop, preserveWindow can be set to true to intercept the process of destroying the desktop layer.
[0171] S306, Activity determines whether preserveWindow is true.
[0172] S307, if preserveWindow=false, the Activity calls WindowMangerGlobal to set the stop state. If preserveWindow=true, the process of stopping the desktop Activity ends and returns to step S301.
[0173] For example, if preserveWindow=false, the Activity can call WindowMangerGlobal to set the stopped state through the function setStoppedState=true.
[0174] S308, WindowMangerGlobal is set to the stopped state.
[0175] After WindowMangerGlobal receives the function setStoppedState=true sent by Activity, WindowMangerGlobal executes the operation of setting the stopped state, which triggers the subsequent process of destroying the desktop layer.
[0176] S309, WindowMangerGlobal calls ViewRootImpl to set the desktop window to stop.
[0177] After WindowMangerGlobal sets the stopped state, you can use the function setWindowStopped = true to notify ViewRootImpl that the desktop window has stopped.
[0178] S310, ViewRootImpl destroys the desktop layer.
[0179] After ViewRootImpl receives setWindowStopped = true sent by WindowMangerGlobal, it calls the destroySurface function to destroy the desktop layer.
[0180] S311, ViewRootImpl calls Surface to release layer resources.
[0181] S312, ViewRootImpl calls SurfaceControl to release layer resources.
[0182] After ViewRootImpl destroys the desktop layer, you can call Surface and SurfaceControl to release the layer resources through the release function.
[0183] S313, Surface releases desktop layer resources.
[0184] After Surface receives the release function, it releases the local desktop layer resources.
[0185] S314, SurfaceControl releases desktop layer resources.
[0186] After receiving the release function, SurfaceControl releases the local desktop layer resources.
[0187] In summary, the embodiment of the present application can determine whether the current Activity to be stopped is a desktop Activity during the process of stopping the desktop Activity. If it is a desktop Activity, the desktop application is intercepted from destroying the desktop layer by setting preserveWindow to true. Otherwise, the desktop layer is destroyed by calling WindowMangerGlobal, ViewRootImpl, Surface, and SurfaceControl.
[0188] It should be noted that, whether the process of destroying the desktop layer is intercepted or the process of destroying the desktop layer is executed, a notification of completing the stopping of the desktop Activity must be sent to AMS.
[0189] In this way, when AMS receives the notification sent by the desktop application that the desktop activity has been stopped, it can Figure 6 The method shown intercepts AMS from destroying the desktop layer.
[0190] like Figure 6 As shown, intercepting AMS from destroying the desktop layer can be achieved by calling multiple classes in AMS, such as ActivityClientController, ActivityRecord, WindowState, WindowStateAnimator, WindowSurfaceController, and SurfaceControl. For details, please refer to the following steps:
[0191] S401, after receiving the notification sent by the desktop application that the desktop Activity has been stopped, the ActivityClientController sends the notification that the desktop Activity has been stopped to the ActivityRecord.
[0192] After the desktop application completes the process of stopping the desktop Activity, the desktop application can switch to the background. At the same time, the desktop application can send the ActivityStopped function to ActivityClientController to notify ActivityClientController that the desktop Activity has been stopped.
[0193] After receiving the ActivityStopped function, ActivityClientController continues to send the ActivityStopped function to ActivityRecord to call ActivityRecord to execute the process of stopping the desktop Activity.
[0194] S402, ActivityRecord calls WindowState to execute layer destruction.
[0195] ActivityRecord can call WindowState to execute layer destruction through the destroySurface function.
[0196] It should be noted that, in some embodiments, an application may include one or more windows. Thus, ActivityRecord may traverse each window and perform layer destruction.
[0197] S403, WindowState determines whether the target layer to be destroyed is the desktop layer.
[0198] After WindowState receives the notification of calling destroySurface, it first determines whether the target layer to be destroyed is the desktop layer.
[0199] In some embodiments, the destroySurface function may include the application package name of the target layer to be destroyed. For example, the application package name of the target layer to be destroyed is the name of the desktop application. In this way, WindowState can determine whether the target layer to be destroyed is a desktop layer by the application package name passed as a parameter.
[0200] S404: If the target layer to be destroyed is the desktop layer, WindowState sets mDestroying = false.
[0201] In this way, if the target layer to be destroyed is the desktop layer, preserveWindow can be set to true to intercept the process of AMS destroying the desktop layer.
[0202] S405, WindowState determines whether mDestroying is true.
[0203] S406, if mDestroying = true, WindowState calls WindowStateAnimator to execute desktop layer destruction. If mDestroying = false, the AMS process of processing the desktop layer ends and returns to step S401.
[0204] S407, WindowStateAnimator destroys the desktop layer.
[0205] WindowStateAnimator executes the operation of destroying the desktop layer, and after completing the destruction of the desktop layer, sends a notification to WindowSurfaceController that the destruction of the desktop layer has been completed.
[0206] S408, WindowStateAnimator sends a notification to WindowSurfaceController that the desktop layer has been destroyed.
[0207] S409, after receiving the notification that the desktop layer has been destroyed, WindowSurfaceController calls SurfaceControl to release the layer resources.
[0208] For example, WindowSurfaceController can call SurfaceControl to release desktop layer resources through the function SurfaceControl.Transationremove().
[0209] S410, SurfaceControl releases desktop layer resources.
[0210] After SurfaceControl receives SurfaceControl.Transationremove(), it releases the desktop layer resources.
[0211] In summary, the embodiment of the present application can determine whether the target layer to be destroyed is the desktop layer during the layer destruction process executed by WindowState. If the target layer to be destroyed is the desktop layer, the desktop layer destruction is intercepted by setting mDestroying = false. Otherwise, the desktop layer can be destroyed by calling WindowStateAnimator, WindowSurfaceController and SurfaceControl.
[0212] The following introduces the internal implementation process of updating the desktop root layout visibility and intercepting the desktop application from executing the relayoutWindow operation based on the change of the desktop root layout visibility.
[0213] like Fig. 7A As shown, the method for the desktop application to update the visibility of the desktop root layout can be implemented by calling multiple classes in the desktop application, such as StopActivityItem, ActivityThread, Activity, and DecorView. For details, please refer to the following steps:
[0214] S501, StopActivityItem calls ActivityThread to stop the desktop Activity.
[0215] S502, ActivityThread calls Activity to execute and stop the desktop Activity.
[0216] S503, during the process of stopping the desktop Activity, the Activity determines whether the target Activity 2 to be stopped is a desktop Activity.
[0217] That is to say, updating the desktop root layout visibility is also performed during the process of stopping the desktop Activity.
[0218] Among them, steps S501 to S503 can refer to the description of steps S301 to S304, which will not be repeated here.
[0219] S504: If Activity2 is the Activity corresponding to the desktop application, ActivityThread does not update the visible state of the desktop root layout, that is, keeps the visible state of the desktop root layout visible.
[0220] It should be noted that when the desktop application is running in the foreground, the desktop root layout visible state is visible. Therefore, when Activity2 is the activity corresponding to the desktop application, ActivityThread does not set the desktop root layout visible, that is, keeps the desktop root layout visible state visible. This is equivalent to not updating the desktop root layout visible.
[0221] S505: If Activity2 is not the Activity corresponding to the desktop application, ActivityThread updates the visible state of the root layout to invisible.
[0222] For example, if the background application is switched to another application (non-desktop application), ActivityThread updates the visible state of the root layout of the other application to invisible.
[0223] S506, after ActivityThread updates the visible state of the root layout to invisible, ActivityThread calls DecorView to set the visible state of the root layout to invisible.
[0224] S507, DecorView sets the visible state of the root layout to invisible.
[0225] The root layout visible state is saved in DecorView.
[0226] Please continue to see Figure 7B, after the desktop application completes steps S501 to S507, and the AMS completes steps S401 to S410, the process of intercepting the desktop application from performing the relayoutWindow operation is executed. Among them, the method of intercepting the desktop application from performing the relayoutWindow operation can be implemented by calling ActivityRecord, WindowToken, WindowState, ViewRootImpl, wm.Session class and WMS. Among them, ActivityRecord, WindowToken and WindowState belong to classes in AMS, ViewRootImpl belongs to classes in desktop applications, and wm.Session belongs to classes in WMS. For details, please refer to the following steps:
[0227] S508, ActivityRecord calls WindowToken to set the visibility state of the desktop.
[0228] S509, WindowToken calls WindowState to send the visibility state of the desktop to the client.
[0229] The client refers to the application process end, for example, a desktop application or other applications.
[0230] S510, WindowState sends the visibility state of the desktop to ViewRootImpl in the desktop application.
[0231] WindowState and ViewRootImpl belong to the classes at both ends. Therefore, WindowState communicates with ViewRootImpl through asynchronous binder.
[0232] S511, ViewRootImpl determines whether the visibility of the desktop root layout has changed.
[0233] In some embodiments, ViewRootImpl can obtain the desktop root layout visibility from DecorView and ViewRootImpl respectively. If the desktop root layout visibility state in ViewRootlmpl is true and the desktop root layout visibility state in DecorView is false, then the desktop's DecorView Visibility Changed = true. If the desktop root layout visibility state in ViewRootlmpl is true and the desktop root layout visibility state in DecorView is true, then DecorViewVisibility Changed = false.
[0234] In some embodiments, if the visible state of the desktop root layout changes, the visible state of the desktop root layout saved in DecorView will be updated. In this way, whether the DecorView Visibility Changed of the desktop is true can be determined based on whether the visible state of the desktop root layout saved in DecorView is updated.
[0235] It should be noted here that ViewRootImpl determines whether the visible state of the root layout has changed, which means determining whether the visible state of the root layout has changed before and after the desktop application is switched to the background. Therefore, no matter what the visibility state of the desktop transmitted by ActivityRecord and WindowToken is, it does not affect the judgment of step S511. In other words, in the above judgment logic, the visibility state of the desktop transmitted by ActivityRecord and WindowToken is invalid.
[0236] S512, if the visible state of the desktop root layout changes, ViewRootImpl notifies WMS to perform the relayoutWindow operation. If the visible state of the desktop root layout does not change, the above process ends and returns to step S508.
[0237] Specifically, ViewRootImpl can call the external interface wm.Session of WMS to notify WMS to perform the relayoutWindow operation.
[0238] S513, WMS executes the relayoutWindow operation.
[0239] Among them, WMS executes the relayoutWindow operation, specifically, the operation of destroying the desktop window.
[0240] The above is a detailed description of the interface switching method for switching from desktop to background provided in the embodiment of the present application.
[0241] Based on the above-mentioned interface switching method of switching from the desktop to the background, the process of switching from the desktop to the foreground is described below.
[0242] Figure 8 A flowchart of an interface switching method for switching the desktop back to the foreground provided in an embodiment of the present application, such as Figure 8 As shown, the following steps may be included:
[0243] S601, the desktop application receives a trigger operation of returning to the desktop input by the user.
[0244] In the embodiment of the present application, the scenarios of returning to the desktop include: Figure 1The scene of returning to the desktop displaying multiple application icons shown also includes the scene of returning to the desktop after entering multitasking, which is not limited in this application.
[0245] S602: The desktop application sends a notification to start the desktop Activity to the AMS.
[0246] It should be understood that in the scenario of switching from desktop to background operation, the desktop application sends the Activity of starting the first application to the AMS. In the scenario of switching from desktop to foreground operation, the desktop application sends the Activity of starting the desktop application to the AMS.
[0247] S603: After receiving the notification for starting the desktop Activity, the AMS sends a notification for creating the desktop Activity to the desktop application.
[0248] S604, after receiving the notification of creating a desktop Activity, the desktop application creates the desktop Activity; and after creating the desktop Activity, sends a notification of the completion of the creation of the desktop Activity to the AMS.
[0249] S605, after receiving the notification that the desktop Activity is created, the AMS sends a notification of playing the animation to the desktop application.
[0250] S606: After receiving the notification to play the animation effect, the desktop application plays the animation effect; and after the animation effect is played, the desktop application sends a notification to the AMS to end the animation effect playing.
[0251] It should be noted that the embodiments of the present application are only exemplified by the case where transition effects are included in the interface switching process. In some embodiments, if transition effects are not included in the interface switching process, the above steps S605 to S606 may not be included. Correspondingly, after receiving the notification that the desktop Activity is created, the AMS sends a notification to the desktop application to execute the startup of the desktop Activity.
[0252] S607, after receiving the notification of the end of the animation playback, the AMS sends a notification to the desktop application to execute and start the desktop Activity.
[0253] For example, the AMS may call the handleStartActivity function to notify the desktop application to execute and start the desktop Activity.
[0254] S608: Keep the desktop root layout visible.
[0255] During the process of launching the desktop Activity, the desktop application does not set the visible state of the desktop root layout, that is, the visible state of the desktop root layout is kept visible.
[0256] S609, after the desktop application completes launching the desktop Activity, it sends a notification of completion of launching the desktop Activity to the AMS.
[0257] For example, the desktop application can notify AMS that the desktop Activity has been started by calling the ActivityStarted function.
[0258] S610, after receiving the notification of completion of starting the desktop Activity, the AMS sends a notification of setting the visible state to the desktop application.
[0259] S611, after receiving the notification of setting the visible state, the desktop application determines whether the visible state of the desktop root layout has changed.
[0260] In the embodiment of the present application, when the desktop application is switched to the background, the desktop root layout visible state is kept visible; and when the desktop application is switched to the foreground, the desktop root layout visible state is also kept visible. Therefore, when the desktop application is switched from the background to the foreground, the desktop root layout visible state is always visible, that is, the desktop root layout visible state does not change.
[0261] S612: If the visible state of the desktop root layout has not changed, the desktop application sends a notification of ending drawing to the WMS.
[0262] If the visible state of the desktop root layout has not changed, the desktop application will not be triggered to perform the relayoutWindow operation. In this way, the desktop application can directly skip the step of performing the relayoutWindow operation and send the finshDraw function to WMS to notify WMS that the drawing is completed.
[0263] S613, the desktop application sends the desktop layer to the WMS.
[0264] Since the desktop application does not perform the relayoutWindow operation, in order to ensure that the desktop can be displayed normally, the desktop application sends the undestroyed desktop layer to the WMS. In this way, the electronic device can still display based on the saved desktop layer.
[0265] S614: If the visible state of the desktop root layout changes, the desktop application sends a notification of executing a relayoutWindow operation to the WMS.
[0266] S615, after receiving the notification to execute the relayoutWindow operation, the WMS executes the relayoutWindow operation to rearrange the windows and obtain the desktop window.
[0267] The relayoutWindow operation in S615 refers to re-layout of the desktop window. After the WMS rebuilds the desktop window, further drawing and rendering are performed, and further drawing and rendering processing can be performed based on the desktop window to obtain a desktop layer.
[0268] In the embodiment of the present application, since the desktop root layout visibility state is kept visible when the desktop application switches to the background, the desktop root layout visibility state does not change when the desktop application switches to the foreground. In this way, when the desktop application switches to the foreground, the desktop application will not be triggered to perform the relayoutWindow operation, and the above steps S614 and S615 will not be performed, thereby saving the time consumed by performing the relayoutWindow operation.
[0269] Furthermore, since the desktop layer is not destroyed when the desktop application switches to the background, even if the desktop application switches to the foreground, the desktop application is not triggered to perform the relayoutWindow operation, and the display can be based on the preserved desktop layer. In this way, when the desktop switches back to the foreground, since the window layout operation is not performed, the preserved desktop layer can be directly used for display, thereby improving the hand tracking response speed.
[0270] In some embodiments, since the desktop layer is not destroyed when the desktop application switches to background operation, the desktop layer data is stored in the memory of the electronic device. The desktop layer data includes desktop layer drawing data and desktop layer rendering data, and the desktop layer rendering data is data further rendered based on the desktop layer drawing data.
[0271] The time consumed to obtain the desktop layer drawing data is much longer than the time consumed to obtain the desktop layer rendering data based on the desktop layer drawing data. Therefore, in order to relieve the memory pressure, the desktop layer rendering data can be released and only the desktop layer drawing data can be retained.
[0272] In one achievable method, the desktop layer rendering data can be released when the desktop life cycle enters the background. Fig. 9 As shown, to release the desktop layer rendering data, you can use the following steps:
[0273] S701, when preserveWindow=true, Activity calls WindowMangerGlobal to clean up memory.
[0274] Combination Figure 4 and Fig. 9, the desktop layer rendering data can be cleaned up during the process of stopping the desktop Activity. Specifically, when preserveWindow=true, the execution of steps S701-S706 is triggered.
[0275] S702, WindowMangerGlobal calls HardwareRender to clean up memory.
[0276] S703, HardwareRender calls RenderProxy to clean up memory.
[0277] S704, RenderProxy calls CanvasContest to clean up memory.
[0278] S705, CanvasContest calls CacheManger to clean up memory.
[0279] S706, CacheManger cleans up the desktop layer rendering data in the memory.
[0280] Among them, WindowMangerGlobal, HardwareRender, RenderProxy and CanvasContest can all call them to clean up memory by sending the function trimMemory() to the latter.
[0281] It should be noted that if the desktop layer rendering data is cleared when the desktop switches to the background, then when the desktop switches back to the foreground, it also includes a step of rendering based on the retained desktop layer drawing data to obtain a rendered desktop layer.
[0282] Fig.10 A flowchart of an interface switching method provided in an embodiment of the present application is shown in FIG. Fig.10 As shown, the method may include the following steps:
[0283] S801, the electronic device displays the desktop.
[0284] When the electronic device displays the desktop, the desktop application runs in the foreground and other applications run in the background. The root layout visibility state corresponding to the desktop application is visible, and the root layout visibility state corresponding to other applications is invisible.
[0285] S802, in response to a start operation input by a user to a first application in the electronic device, displaying an interface of the first application; wherein, after receiving the start operation, the desktop application in the electronic device does not perform a window rearrangement operation.
[0286] After receiving the start operation, the desktop application will be switched to the background and the first application will be switched to the foreground.
[0287] In the embodiment of the present application, after receiving the start operation, the visible state of the desktop root layout is maintained as visible, and the visible state of the root layout of the first application is set to be visible.
[0288] In this way, after receiving the start operation, since the visible state of the desktop root layout has not changed, the desktop application does not perform a window re-layout operation, that is, does not destroy the desktop window. Since the visible state of the first application's root layout changes from invisible to visible, that is, the visible state of the first application's root layout changes, the first application performs a window re-layout operation, that is, creates a window corresponding to the first application.
[0289] In the embodiment of the present application, after receiving the start operation, the desktop application will be intercepted to destroy the desktop layer. The method of intercepting the desktop application to destroy the desktop layer can refer to the description of steps S208-S211 and steps S301-S314, which will not be repeated here.
[0290] In the embodiment of the present application, after receiving the start operation, the AMS will be intercepted from destroying the desktop layer. The method of intercepting the AMS from destroying the desktop layer can be referred to the description of steps S214-S217 and steps S401-S410, which will not be repeated here.
[0291] In this way, after receiving the start operation, the desktop layer can be saved in the memory of the electronic device because the desktop layer is not destroyed.
[0292] S803, in response to an input trigger operation of returning to the desktop, displaying the desktop; wherein, after receiving the trigger operation of returning to the desktop, the desktop application does not perform a window re-layout operation, and the first application performs a window re-layout operation.
[0293] After receiving the trigger operation of returning to the desktop, the desktop application will be switched to the foreground and the first application will be switched to the background.
[0294] In an embodiment of the present application, after receiving a trigger operation to return to the desktop, the visible state of the desktop root layout is maintained as visible, and the visible state of the root layout of the first application is set to invisible.
[0295] In this way, after receiving the trigger operation to return to the desktop, since the visible state of the desktop root layout has not changed (it is always visible), the desktop application does not perform a window re-layout operation, that is, does not re-create the desktop window. Since the visible state of the first application's root layout changes from visible to invisible, that is, the visible state of the first application's root layout changes, the first application performs a window re-layout operation, that is, destroys the window corresponding to the first application.
[0296] Furthermore, in order to display the desktop normally, after receiving the trigger operation to return to the desktop, although the desktop application does not recreate the desktop window, it can obtain the saved desktop layer from the memory of the electronic device, and then display it based on the saved desktop layer.
[0297] In some embodiments, the saved desktop layer is a rendered desktop layer. In this case, the rendered desktop layer can be directly sent to the display screen for display.
[0298] In some embodiments, the saved desktop layer is a drawn desktop layer, in which case rendering processing can be performed based on the drawn desktop layer to obtain a rendered desktop layer, and then the rendered desktop layer is sent to the display screen for display.
[0299] Among them, the specific implementation process of step S803 can be found in the description of steps S601-S615 and steps S701-S706, which will not be repeated here.
[0300] The various method embodiments described in this document may be independent solutions or may be combined according to internal logic, and these solutions all fall within the protection scope of this application.
[0301] It can be understood that, in the above-mentioned various method embodiments, the methods and operations implemented by the electronic device can also be implemented by components (such as chips or circuits) that can be used in the electronic device.
[0302] The above embodiments introduce the interface switching method provided by the present application. It is understandable that, in order to implement the above functions, the electronic device includes a hardware structure and / or software module corresponding to each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0303] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software. The steps of the method disclosed in conjunction with the embodiment of the present application can be directly embodied as a hardware processor for execution, or a combination of hardware and software modules in a processor for execution. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory and completes the steps of the above method in conjunction with its hardware. To avoid repetition, it is not described in detail here.
[0304] It should be noted that the processor in the embodiment of the present application can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method embodiment can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor can be combined and performed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0305] It can be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0306] According to the method provided in the embodiments of the present application, the embodiments of the present application also provide a computer program product, which includes: a computer program or instructions, when the computer program or instructions are run on a computer, the computer executes the method of any one of the embodiments of the method.
[0307] According to the method provided by the embodiments of the present application, the embodiments of the present application also provide a computer storage medium, which stores a computer program or instructions. When the computer program or instructions are run on a computer, the computer executes the method of any one of the embodiments of the method.
[0308] According to the method provided by an embodiment of the present application, an embodiment of the present application also provides an electronic device, including a memory and a processor; the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device executes the method of any one of the embodiments of the method embodiment.
[0309] Those of ordinary skill in the art will appreciate that the various illustrative logical blocks and steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel may 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.
[0310] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.
[0311] The computer storage medium, computer program product, and electronic device provided in the above-mentioned embodiments of the present application are all used to execute the method provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the method provided above, and will not be repeated here.
[0312] It should be understood that in each embodiment of the present application, the execution order of each step should be determined by its function and internal logic, and the size of the sequence number of each step does not mean the order of execution and does not limit the implementation process of the embodiment.
[0313] Each part of this specification is described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the device, computer storage medium, computer program product, and electronic device, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiments.
[0314] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0315] The above-described embodiments of the present application do not constitute a limitation on the protection scope of the present application.
Claims
1. An interface switching method, It is characterized in that The method is applied to an electronic device, and the method comprises: The electronic device displays a desktop; In response to a user input start operation of a first application in the electronic device, the interface of the first application is displayed; wherein, after receiving the start operation, the desktop application executes an operation of stopping the active Activity, and in the process of the desktop application executing the operation of stopping the Activity, if the desktop application determines that the target stopped Activity is a desktop Activity, the desktop application keeps the desktop root layout visible state as visible; wherein, if the desktop root layout visible state does not change, the desktop application does not execute the window re-layout operation; after the desktop application completes the operation of stopping the Activity, the desktop application sends a notification of the completion of stopping the Activity to the activity management service in the electronic device; after the activity management service receives the notification of the completion of stopping the Activity, if the activity management service determines that the target destroyed layer is a desktop layer, the activity management service sets the layer destruction state to not destroyed; wherein, if the layer destruction state is not destroyed, the activity management service does not destroy the desktop layer in the activity management service; In response to an input trigger operation for returning to the desktop, the desktop is displayed based on the desktop layer that has not been destroyed; wherein, after receiving the trigger operation for returning to the desktop, the desktop application does not perform a window re-layout operation, and the first application performs a window re-layout operation.
2. The method according to claim 1, It is characterized in that After receiving the start operation, the method further includes: If the desktop application determines that the target stopped Activity is a desktop Activity, the desktop application sets the saved window state to a saved state; wherein, when the saved window state is the saved state, the desktop application does not destroy the desktop layer in the desktop application.
3. The method according to claim 1, It is characterized in that After receiving a trigger operation to return to the desktop, the method further includes: The desktop application keeps the desktop root layout visible as visible; wherein, when the desktop root layout visible state does not change, the desktop application does not perform a window re-layout operation; The first application sets the visible state of the root layout of the first application to be invisible; wherein, when the visible state of the root layout of the first application changes, the first application performs a window re-layout operation.
4. The method according to claim 3, It is characterized in that The step of displaying the desktop in response to the input trigger operation of returning to the desktop comprises: In response to an input trigger operation of returning to the desktop, obtaining a desktop layer from a memory of the electronic device; Based on the desktop layer, the desktop is displayed.
5. The method according to claim 1, It is characterized in that The memory of the electronic device includes desktop layer drawing data and desktop layer rendering data, and the method further includes: During the process of the desktop application executing the operation of stopping the Activity, if the desktop application determines that the target stopped Activity is a desktop Activity, the desktop layer rendering data in the memory of the electronic device is cleared.
6. The method according to claim 5, It is characterized in that The step of displaying the desktop in response to the input trigger operation of returning to the desktop comprises: In response to an input trigger operation of returning to the desktop, acquiring the desktop layer drawing data; Based on the desktop layer drawing data, a rendering operation is performed to obtain a rendered desktop layer; The desktop is displayed based on the rendered desktop layer.
7. An electronic device, It is characterized in that The electronic device comprises a memory and a processor; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code comprises computer instructions, and when the processor executes the computer instructions, the electronic device executes the method as described in any one of claims 1-6.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program or instruction. When the computer program or instruction is executed, the method according to any one of claims 1 to 6 is executed.
