Method and device for managing threads
By detecting whether the process of the second application exists in the smart terminal device and there is no active interface, the priority of its UI thread is improved in advance, and the problems of high CPU usage and slow user interface response when multiple applications are run are solved, which improves the problem of high CPU usage and slow user interface response when multiple applications are run, User experience.
Patent Information
- Application Number
- CN202310644140.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2024-12-03
AI Technical Summary
In smart terminal devices, the operation of multiple applications results in high CPU usage, untimely resource scheduling, low user interface thread priority, slow response, affecting user experience.
By detecting the user's intent event to start the applet, it is determined whether the process of the second application exists and does not have an active interface, and the priority of its UI thread is increased in advance, thereby prioritizing scheduling in the system.
It improves the startup speed of the mini program, improves the user experience, and reduces the loading time of the user interface.
Smart Images

Figure CN119065822A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular, to a method and device for managing threads. Background Art
[0002] With the rapid development of smart terminal performance, multiple processes can be run in smart terminals to respond to user needs. Under load scenarios, the CPU usage of smart terminals is relatively high, and there are many tasks to be processed. For example, if a user opens 20 applications at the same time, due to untimely resource scheduling, the user interface (UI) thread of the application will continue to be at a low priority, responding slowly, seriously affecting the user experience. Summary of the invention
[0003] In view of this, the present application provides a method, device, electronic device, computer-readable storage medium and computer program product for managing threads, which can increase the priority of the UI thread as soon as the user's intention to start a mini-program is identified, which helps to increase the startup speed of the mini-program and enhance the user experience.
[0004] In a first aspect, a method for managing threads is provided, comprising:
[0005] When it is detected that the process of the first application initiates an operation of starting an activity interface in the process of the second application (specifically, the interface of the first application), determining whether the process of the second application exists;
[0006] When the process of the second application exists, determining whether the activity interface (Activity) exists in the process of the second application;
[0007] When the active interface does not currently exist in the process of the second application, determining the priority of the user interface UI thread of the process of the second application from the first priority to the second priority, where the second priority is higher than the first priority;
[0008] Based on the second priority, the UI thread of the process of the second application is scheduled.
[0009] The above technical solution can be executed by a terminal device or a chip in the terminal device. Based on the above solution, when the user's intention event to start the mini-program is identified for the first time (specifically, when it is detected that the process of the first application initiates the operation of starting the active interface in the process of the second application, it is determined that the process of the second application exists and there is no active interface in the process of the second application), the priority of the UI thread of the process of the second application is increased. Compared with the current method of setting the priority of the UI thread of the process of the second application at the thread grouping, the embodiment of the present application can set the priority of the UI thread of the process of the second application in advance, so that the system can prioritize the scheduling of the UI thread of the process of the second application, thereby improving the startup speed of the mini-program and helping to improve the user experience.
[0010] In some possible implementations, before detecting that the process of the first application program initiates an operation of launching an activity interface in the process of the second application program, the method further includes:
[0011] It is detected that the process of the first application triggers the process of the second application in an inactive manner.
[0012] Optionally, in some possible implementations, detecting that the process of the first application triggers the process of the second application includes: detecting that the process of the first application triggers the process of the second application in an inactive manner.
[0013] Optionally, detecting that the process of the first application triggers the process of the second application in an inactive manner includes:
[0014] It is detected that the process of the first application starts the process of the second application through the system's startup service mode, broadcast mode or content provider.
[0015] Exemplarily, the process of the first application can start the process of the second application through the startService method. In the current resource scheduling, due to the untimely resource grouping scheduling, the process started through the startService method is at a lower priority for a long time, so that the UI thread of the process of the second application is in a runnable state for a long time. For the UI thread started through the startService method, when it is judged that the conditions for adjusting the priority are met, the embodiment of the present application increases its calling priority in advance so as to increase its startup speed and improve the user experience.
[0016] The embodiment of the present application does not specifically limit the type of application program. The application program may be a third-party application program or a system application program.
[0017] In some possible implementations, detecting that a process of a first application triggers a process of a second application includes:
[0018] In response to detecting a first operation of the user, the process of the second application is triggered by the process of the first application, where the first operation is an operation of clicking an application icon corresponding to a target applet.
[0019] In some possible implementations, the first application is a third-party application, and the UI thread of the process of the second application is the UI thread of the target applet in the first application.
[0020] Therefore, for the scenario where a third-party application launches a mini-program, for example, launching a mini-program through startService, after adopting the method of managing threads in the embodiment of the present application, the startup speed of the mini-program can be effectively improved, thereby enhancing the user experience.
[0021] In some possible implementations, the first application is a system application, and the UI thread of the process of the second application is a UI thread in the system application.
[0022] Therefore, for the scenario of the system application startup interface, for example, the system_server pop-up application permission window, after adopting the method of managing threads in the embodiment of the present application, the startup speed of the window can be effectively improved, thereby improving the user experience.
[0023] In some possible implementations, determining whether the activity interface exists in the process of the second application program includes:
[0024] By identifying whether the process of the second application includes a task stack, it is determined whether an Activity instance currently exists in the process of the second application.
[0025] Therefore, by identifying whether the process of the second application includes a task stack, it is possible to know whether there is an Activity instance in the current application process, so as to prepare for whether to increase the priority of the application UI thread later.
[0026] In a second aspect, a thread management device is provided, comprising a unit for executing the method in any one of the implementations of the first aspect. The device may be an electronic device (such as a terminal device) or a chip in an electronic device (such as a chip in a terminal device). The device comprises an input unit, a display unit, and a processing unit.
[0027] When the device is an electronic device, the processing unit may be a processor, the input unit may be a communication interface, and the display unit may be a graphics processing module and a screen; the electronic device may also include a memory for storing computer program code, and when the processor executes the computer program code stored in the memory, the electronic device executes the method in any one of the implementations of the first aspect.
[0028] When the device is a chip in an electronic device, the processing unit may be a logic processing unit inside the chip, the input unit may be an input interface, a pin or a circuit, etc., and the display unit may be a graphics processing unit inside the chip; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes the method in any one of the implementations of the first aspect.
[0029] In a third aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code, and when the computer program code is executed by a thread management device, the device executes the method in any one of the implementation modes in the first aspect.
[0030] In a fourth aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by a thread management device, the device executes the method in any one of the implementation modes in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 It is an example diagram of an application scenario of an embodiment of the present application;
[0032] Figure 2 is a schematic diagram of a hardware system of an electronic device applicable to the present application;
[0033] Figure 3 is a schematic block diagram of the software structure of an electronic device applicable to the present application;
[0034] Figure 4 is a schematic diagram of another software system of an electronic device applicable to the present application;
[0035] Figure 5 is a schematic flow chart of a method for managing threads according to an embodiment of the present application;
[0036] Figure 6 is a timing example diagram of a method for managing threads according to an embodiment of the present application;
[0037] Figure 7 is another flow chart comparing the embodiment of the present application with the existing flow chart;
[0038] Figure 8 It is a schematic diagram of a specific implementation process of an embodiment of the present application;
[0039] Fig. 9 This is an example diagram of an application scenario in which the method for managing threads in an embodiment of the present application is applicable;
[0040] Fig.10 This is another example diagram of an application scenario to which the method for managing threads in an embodiment of the present application is applicable;
[0041] Fig.11 This is another example diagram of an application scenario to which the method for managing threads in an embodiment of the present application is applicable;
[0042] Fig.12 This is another example diagram of an application scenario to which the method for managing threads in an embodiment of the present application is applicable;
[0043] Fig.13 This is another example diagram of an application scenario to which the method for managing threads in an embodiment of the present application is applicable;
[0044] Fig.14 It is a schematic block diagram of a device for managing threads according to an embodiment of the present application. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0046] The method for managing processes provided in the embodiments of the present application can be applied to electronic devices. For example, the electronic device can be a tablet computer, a laptop computer, a wearable device, a multimedia playback device, an e-book reader, a personal computer (PC), a personal digital assistant (PDA), a netbook, an augmented reality (AR) device, a virtual reality (VR) device, a smart phone, a smart TV, a smart screen device, a smart camera, a portable multimedia player (PMP), a projection device, a mixed reality (MR) device, a television or a somatosensory game console in a human-computer interaction scene and other electronic devices. The present application does not limit the specific form of the electronic device.
[0047] The method for managing threads in the embodiment of the present application can be applied to an application scenario where an electronic device starts a UI thread of an application under a load scenario. It can be understood that the embodiment of the present application does not limit the specific type of application. The application can be a third-party application or a system application.
[0048] Optionally, the embodiments of the present application may be applied to a scenario where an activity (startActivity) is started in a UI thread after a process is started in an inactive manner (e.g., a startService manner, a broadcast or a content provider manner). Generally speaking, a process may include one or more threads. The one or more threads include a UI thread, also referred to as a main thread. The UI thread is used to distribute events (e.g., drawing events) to UI components of the Android system.
[0049] Generally speaking, the mini-programs of applications started via the startService method will have problems with slow startup and untimely response. This is because the system sets the UI thread of the application started via the startService method as a background thread, so the priority will be lower than the priority of the real-time thread at startup. Especially when there are many pending tasks on the electronic device, the mini-program continues to be at a low priority and it takes a long time to be runnable, and this problem is particularly prominent. For users, if the user clicks on a mini-program in the application, they will expect to start the mini-program as soon as possible and present the corresponding UI interface.
[0050] For ease of understanding, the following describes the application scenario of the embodiment of the present application in combination with 1. In the current electronic device, the CPU has many tasks to be processed, and the user opens the Alipay application as an example for explanation. Figure 1 , Figure 1 (1) shows the main interface of the Alipay application. Figure 1 As shown in (1), the main interface of Alipay includes shortcut icons of multiple mini-programs, such as Mini-program 1, Mini-program 2, Mini-program 3, Mini-program 4, Mini-program 5, Mini-program 6, and the sports mini-program. When a user clicks on one of the mini-programs, such as the sports mini-program, the Alipay process will start the mini-program process through the startService method. The mini-program process started in this way has a low priority when it is started. Therefore, the interface will display the following Figure 1 The interface shown in (2) is that the page shows that the sports applet is loading and remains loading for a long time.
[0051] In view of this, the thread management method of the embodiment of the present application, when the user's intention event to start the mini program is identified for the first time (for example, when it is detected that the process of application A initiates the operation of starting the activity interface in the interface, it is determined that the UI thread of application B exists and the activity interface Activity does not yet exist in application B), the priority of the UI thread of application B is increased so that the system can prioritize the scheduling of the UI thread of application B, thereby increasing the startup speed of application B and helping to improve the user experience. Application A can be an example description of the first application below; application B can be an example description of the second application below.
[0052] Before introducing the method for managing threads according to the embodiment of the present application, the hardware system and software structure of the embodiment of the present application are first introduced.
[0053] Figure 2 A hardware system suitable for the device of the present application is shown.
[0054] The device 100 may be a mobile phone, a smart screen, a tablet computer, a wearable electronic device, an in-vehicle electronic device, an augmented reality (AR) device, a virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a projector, etc. The embodiment of the present application does not impose any limitation on the specific type of the device 100.
[0055] The 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. The sensor module 180 may include 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, a bone conduction sensor 180M, etc.
[0056] It should be noted that Figure 2 The structure shown does not constitute a specific limitation on the device 100. In other embodiments of the present application, the device 100 may include Figure 2 More or fewer components than those shown, or the apparatus 100 may include Figure 2 Combinations of some of the components shown, or the apparatus 100 may include Figure 2 Subassemblies of some of the components shown. Figure 2 The components shown may be implemented in hardware, software, or a combination of software and hardware.
[0057] The processor 110 may include one or more processing units. For example, the processor 110 may include at least one of the following processing units: an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and a neural-network processing unit (NPU). Different processing units may be independent devices or integrated devices.
[0058] In some possible embodiments, the processor 110 is used to determine whether a process of a second application exists when it is detected that the first application initiates an operation to start an active interface in the user interface of the first application, and further determine whether an active interface exists in the process of the second application when the process of the second application exists; when there is no active interface in the process of the second application, increase the priority of the UI thread of the process of the second application.
[0059] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0060] The processor 110 may also be provided with a memory 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 cyclically used. 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.
[0061] In some embodiments, processor 110 may include one or more interfaces.
[0062] Figure 2 The connection relationship between the modules shown is only a schematic illustration and does not constitute a limitation on the connection relationship between the modules of the device 100. Optionally, the modules of the device 100 may also adopt a combination of multiple connection modes in the above embodiments.
[0063] The device 100 can implement display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0064] The display screen 194 can be used to display images or videos. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a mini light-emitting diode (Mini LED), a micro light-emitting diode (Micro LED), a micro OLED (Micro OLED) or a quantum dot light emitting diode (QLED). In some embodiments, the device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0065] In some embodiments, display screen 194 may be used to display an interface of a UI thread of a second application.
[0066] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, for example, they can be resistive pressure sensors, inductive pressure sensors or capacitive pressure sensors. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When the force acts on the pressure sensor 180A, the capacitance between the electrodes changes, and the device 100 determines the intensity of the pressure according to the change in capacitance. When the touch operation acts on the display screen 194, the device 100 detects the touch operation according to the pressure sensor 180A. The device 100 can also calculate the position of the touch according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on a short message application icon, an instruction to view the short message is executed; when a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on a short message application icon, an instruction to create a new short message is executed.
[0067] The touch sensor 180K is also called a touch control device. The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, which is also called a touch control screen. The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K 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 180K can also be set on the surface of the device 100 and set at a different position from the display screen 194.
[0068] The hardware system of the device 100 is described in detail above, and the software system of the device 100 is introduced below. The software system can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture or a cloud architecture. The embodiment of the present application takes the layered architecture as an example to exemplarily describe the software system of the device 100.
[0069] like Figure 3 As shown, the software system using the layered architecture is divided into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software system can be divided into five layers, from top to bottom, namely, the application layer, the application framework layer and the Java system service layer, the local service layer (native service or native libraries), the hardware abstraction layer, and the driver layer.
[0070] The application layer may include a series of application packages. For example, the application layer may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0071] In order to show some selection information or prompt information to the user, the terminal will dynamically display some small windows. Figure 3 As shown, the application layer may include an activity module (or component), a Dialog module, a PopupWindow module, a view module, and a view group (ViewGroup).
[0072] Activity is used to display the interface for user interaction. For example, Activity is a full-screen or split-screen interface. Dialog or PopupWindow is a window (such as a pop-up window) used to prompt or notify users of information, which can be displayed or attached to Activity. In other words, Activity can also be considered a window different from Dialog or PopupWindow.
[0073] Dialog or PopupWindow windows can include View and ViewGroup. Among them, View is the basic element that constitutes the interface. View contains rich controls that can respond to user operation events. For example, when the system interacts with the user, the system will pass the event to the View module, and then the View module will respond accordingly. In other words, View is the basic building block of the user interface component, responsible for image interface rendering and event processing. For example, View occupies a rectangular area on the screen, such as a button or text box. Users can operate the interface through the View module.
[0074] ViewGroup includes multiple Views (sub-controls). ViewGroup can be considered as a special View that can accommodate other Views.
[0075] It can be understood that an Activity may also include a View and a ViewGroup (not shown in the figure for simplicity).
[0076] 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 may include some predefined functions.
[0077] like Figure 3 As shown, the application framework layer and the Java system service layer include an activity manager, a window management service (window manager service, WMS), a window animation (Window Animation) module, a resource module, a package manager service (package manager service, PMS), and an input manager.
[0078] The activity manager can provide activity management services (AMS), which can be used to start, switch, and schedule system components (such as activities, services, content providers, and broadcast receivers) as well as manage and schedule application processes.
[0079] WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system. WMS can create and manage windows. WMS is a service provided by the window manager. The window manager can also obtain the display size, determine whether there is a status bar, lock the screen, and capture the screen.
[0080] The input manager can provide input management services (IMS). IMS can be used to manage system input, such as touch screen input, key input, sensor input, etc. IMS takes events from input device nodes and distributes them to appropriate windows through interaction with WMS.
[0081] Optionally, the application framework layer also includes a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.
[0082] Content providers are used to store and retrieve data and make it accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, and phone books.
[0083] The view system includes visual controls, such as controls for displaying text and controls for displaying images. 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.
[0084] The phone manager is used to provide communication functions of the device 100, such as management of call status (connected or disconnected).
[0085] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, and video files.
[0086] 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 for download completion notifications and message reminders. The notification manager can also manage notifications that appear in the system's top status bar in the form of icons or scrolling text, such as notifications from applications running in the background. The notification manager can also manage notifications that appear on the screen in the form of dialog windows, such as prompting text messages in the status bar, emitting reminder sounds, vibrating electronic devices, and flashing indicator lights.
[0087] The application layer and the application framework layer run in the 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.
[0088] The local service layer may include multiple functional modules, such as: 3D graphics processing library (e.g., open graphics library for embedded systems (OpenGL ES), 2D graphics engine (e.g., skia graphics library (SGL)), display synthesis system (surface flinger) module, media library (Media Libraries), browser kernel (Webkit), Android runtime (Android Runtime) and core library.
[0089] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for scheduling and management of the Android system.
[0090] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0091] The 3D graphics processing library can be used to implement 3D graphics drawing, image rendering, compositing and layer processing.
[0092] A 2D graphics engine is a drawing engine for 2D drawings.
[0093] Surface flinger can also be called layer blending module. Surface flinger module is used to blend layers and send the blended layers to display so that the content in the window can be displayed on the display screen. Dialog and Popupwindow will correspond to a layer instance in the surface flinger module.
[0094] The media library supports playback and recording of multiple audio formats, playback and recording of multiple video formats, and still image files. The media library can support multiple audio and video coding formats, such as: MPEG4, H.264, moving picture experts group audio layer III (MP3), advanced audio coding (AAC), adaptive multi-rate (AMR), joint photographic experts group (JPG) and portable network graphics (PNG).
[0095] The browser kernel is used to call the system browser.
[0096] The hardware abstraction layer is a package of hardware drivers, providing a unified general interface for the upper layer. Figure 3 As shown, the hardware abstraction layer includes camera HAL, display HAL, audio HAL, sensor HAL, etc.
[0097] The driver layer is the bottom layer of the software stack. The driver layer is used to manage and control hardware devices. The driver layer can include driver modules such as camera driver, display driver, Binder driver, audio driver and sensor driver.
[0098] Figure 3 In the software architecture shown in , the application layer and the system service layer can communicate across processes. The communication method can use an inter-process communication mechanism (Binder) or rely on a Binder driver to achieve communication.
[0099] Figure 3 The software structure of the terminal device is described in . In order to reflect the work done by the software in the terminal device when processing tasks related to the UI thread, refer to Figure 4 . Figure 4 This is another system architecture diagram of a terminal device software system provided in an embodiment of the present application (hereinafter referred to as system architecture). In the embodiment of the present application, the system architecture of the terminal device includes: an application layer, an application framework layer, a native layer (i.e., a system library), and a kernel layer.
[0100] The application layer is used to provide applications, including but not limited to system applications and third-party applications.
[0101] The application framework layer is used for system services and provides various application programming interfaces (APIs) that may be used when building applications. The Framework layer has an activity manager service (AMS) component, which is located in the system server of the Framework layer. The AMS component can be used to create applications and switch applications. There are also system servers and iAware processes modules.
[0102] The system service includes the Android architecture, the Android architecture includes the real-time system, and the real-time system includes an activity verification module and a setting grouping module (or a high-priority grouping setting). The activity verification module is used to determine whether the target process (for example, the target process is the process of the second application) exists, and whether there is an activity in the target process. When the target process exists and there is no activity in the target process, the activity verification module passes the verification. Exemplarily, when it is detected that the process of the first application initiates the startActivity operation in the user interface, it is determined whether the target process exists; when the target process exists, it is determined whether there is an activity in the target process.
[0103] The grouping module is set to increase the priority of the UI thread when the activity verification module passes the verification. For example, when the target process exists and there is no activity in the target process, the priority of the UI thread of the target process is increased.
[0104] The iAware process includes a non-real-time processing subsystem, which includes configuration management and feature switches. The Framework layer also includes mechanisms for implementing inter-process communication, such as the Binder mechanism. The configuration management module is used for system initialization and configuration, such as restarting the system. The feature switch is used to add a configuration file to the system configuration file to implement the method for managing threads in the embodiment of the present application.
[0105] The native layer is used to provide local services and link dynamic libraries. The Native layer has the Android runtime (ART) virtual machine, native libraries (Libs) and awareness services (daemon). The ART virtual machine can provide an execution environment for Java programs. The native library includes a message distribution module, such as the iAware Daemon module. The message distribution module can also have other names, such as a receiver distributor. The message distribution module can be understood as a channel for message distribution to the kernel layer.
[0106] Optionally, the local library includes a local link dynamic library (libAndroid_Runtime) and a layer synthesis service (SurfaceFlinger, SF) (or surface ejector), media services, etc., wherein SF is used to synthesize rendering data into various layers.
[0107] The kernel layer provides the underlying drivers for various hardware of electronic devices. The kernel layer also has Linux drivers, thread drivers, kernel extension subsystems, scheduling modules, and double data rate (DDR) memory management modules.
[0108] The scheduling module is used to implement thread scheduling in the Android system. The scheduling module includes the real-time scheduling module and the VIP thread scheduling module. The real-time scheduling module is used to schedule certain events that require real-time response to ensure timely response. The VIP thread scheduling module is used to schedule threads that require priority scheduling.
[0109] The thread driver is used to manage the binder thread priority.
[0110] In an embodiment of the present application, in order to realize the new function of managing threads in the embodiment shown in the present application, corresponding modifications are made to the real-time system, configuration management, feature switches, message distribution module, scheduling module and thread driver to meet the requirements of each step of the embodiment of the present application.
[0111] The following combination Figures 5 to 13 A method for managing threads according to an embodiment of the present application is described.
[0112] See also Figure 5 , Figure 5 FIG. 1 is a schematic flow chart of a method for managing threads according to an embodiment of the present application. Figure 5 As shown, the method includes:
[0113] Optionally, in step 501, it is detected that the process of the first application triggers the process of the second application.
[0114] The type of application (first application or second application) in the embodiment of the present application is not specifically limited. The application can be a system application or a third-party application. Exemplarily, when the electronic device runs application A, the process of the first application is started.
[0115] Optionally, in some embodiments, the first application is a third-party application, and the UI thread of the process of the second application is the UI thread of the target applet in the third-party application. The UI thread is also called the main thread.
[0116] For example, the first application is the Alipay APP. The second application is a target applet in Alipay. The user can start the target applet by clicking on the shortcut of the target applet.
[0117] Optionally, when the first application is a third-party application, a first operation of the user is detected, the first operation being an operation in which the user clicks on an application icon (or shortcut) corresponding to the target applet; in response to detecting the first operation, it is detected that the process of the first application triggers the second application. For example, the first operation may be Fig. 9 The operation of clicking the Alipay Sports applet shown in (1) is shown in FIG. 1 . For another example, the first operation may be Fig.10 The operation of clicking on the Honor Mall applet as shown in (2).
[0118] Optionally, in some embodiments, the first application is a system application; accordingly, the UI thread of the process of the second application is a UI thread in the system application.
[0119] For example, the first operation can be Fig.11 The operation of clicking the "My" control 201 shown in (2) in FIG. 10 is another example. The first operation may be Fig.12 The operation of clicking the "Glory Share" control 1202 shown in (2).
[0120] The UI thread can also be called the interface thread (Activity Thread). The UI thread is the main thread of the application. The UI thread can be understood as the thread that is about to create the interface but has not yet been completed.
[0121] Optionally, the process of the first application starts the process of the second application by initiating an intent (Intent), and then starts the interface (or Activity) in the UI thread of the process of the second application.
[0122] The embodiment of the present application does not limit the specific manner in which the process of the first application triggers (or launches, or starts) the second application.
[0123] Optionally, in some embodiments, step 501 includes: detecting that the process of the first application program triggers the process of the second application program by starting inactively.
[0124] The embodiment of the present application does not limit the specific form of the inactive mode (non-activity mode). The process started in the inactive mode is a background process. A background process is a process running in the background or a process that is not actively displayed on the screen.
[0125] Optionally, detecting that the process of the first application triggers the process of the second application in an inactive manner specifically includes: detecting that the process of the first application triggers the process of the second application through the system's startup service, broadcast or content provider.
[0126] For example, the first application interacts with the system and requests the system to start the process of the second application through the startService method. In the current resource scheduling, due to the untimely scheduling of resource groups, the UI thread is located in the background group when responding, and is at a lower priority for a long time, so that the UI thread is in a runnable state for a long time. The embodiment of the present application is aimed at the current system UI thread without an interface. When it is judged that it meets the conditions for adjusting the priority, the priority of its call is increased in advance to increase its startup speed and improve the user experience.
[0127] For another example, the process of the first application program starts the process of the second application program through broadcasting. The explanation of starting an application program through broadcasting can refer to the relevant technology.
[0128] For another example, the process of the first application program starts the process of the second application program through a content provider. For an explanation of starting an application program through a content provider, reference may be made to related technologies.
[0129] It should be understood that the above-mentioned examples of inactive modes are merely illustrative descriptions, and the embodiments of the present application are not limited thereto.
[0130] In the embodiment of the present application, the conditions for adjusting the priority of the UI thread of the process of the second application can be considered from the following two factors: (1) the process of the second application exists; (2) the interface (or Activity) currently does not exist in the process of the second application. The conditions for adjusting the priority will be explained in detail later.
[0131] It is understandable that the specific method of the application program to start the UI thread is not limited in the embodiment of the present application. In addition to the process started by the application program through the startService method, it can also be applicable to the process without Activity started by the application program through other methods.
[0132] Step 502: When the process of the first application initiates an operation of starting an activity interface in the process of the second application, it is determined whether the process of the second application exists.
[0133] The activity interface may also be referred to as interface. The method in which the first application starts the activity interface may be startActivity.
[0134] Optionally, after the process of the first application starts the process of the second application, an operation of creating an interface is also initiated in the second application. For example, application A starts an interface in the UI thread of application B by using the startActivity method.
[0135] Generally speaking, the time when the process of the first application initiates the interface startup in the process of the second application is the earliest time point when the system can detect the user's intention to start the mini-program. Therefore, when the process of the first application initiates the startup of the Activity in the process of the second application, the embodiment of the present application intends to determine whether the process of the second application exists at this time point, and further determine whether there is an active interface in the process of the second application when the process of the second application exists, so as to increase the priority of the UI thread of the process of the second application at the first time.
[0136] The existence of the second application process can be understood as: the second application process has been created, or the first application process has successfully created the second application process. For example, the first application process starts the second application process through the startService method; Zygote creates the second application process through the createProcess function, and the second application process is still a background process; and a series of initialization processes are performed to complete the application logic construction environment in the subsequent process.
[0137] Optionally, step 501 may occur before step 502 .
[0138] Optionally, step 502 and step 503 may also be implemented simultaneously, that is, in no particular order.
[0139] Step 503: when the process of the second application exists, determine whether the activity interface (Activity) (the activity interface may also be referred to as interface) exists in the process of the second application.
[0140] The embodiment of the present application is directed to the scenario where the process of the second application exists and there is no interface in the process of the second application but there will be one. That is, when it is determined that the process of the second application exists, it is necessary to further determine whether there is an Activity in the process of the second application.
[0141] In other words, in the embodiment of the present application, when it is determined that the process of the second application exists and there is no Activity in the process of the second application, the priority of the UI thread of the process of the second application will be increased. In other cases, for example, when the process of the second application does not exist, or when the process of the second application exists and there is also an interface in the process of the second application, the solution of the embodiment of the present application will not be executed.
[0142] The fact that the second application process does not have an Activity means that the Activity instance in the second application process has not been successfully created. For example, although the second application process has initiated a process of creating an Activity instance in the UI thread, the Activity instance has not been successfully created.
[0143] Optionally, in some embodiments, it can be determined whether the Activity instance currently exists in the process of the second application by identifying whether the process includes a task stack (TASK).
[0144] Generally speaking, a task stack (TASK) refers to a task stack that contains one or more Activities. An Activity refers to a screen or user interface in an application. Each Activity belongs to its own task stack. When a user starts an application, the system creates a new task stack (TASK) and puts the application's startup Activity into the task stack. A process is the smallest unit of resource allocation, so the Activity interface should be judged by the process.
[0145] For example, whether there is an Activity interface can be determined by identifying whether the process contains a task stack. If there is a task stack, it is considered that there is an Activity interface; if there is no task stack, it is considered that there is no Activity interface.
[0146] Step 504: when there is currently no active interface in the process of the second application, the priority of the UI thread of the process of the second application is determined from the first priority to the second priority, and the second priority is higher than the first priority.
[0147] Here is a unified explanation. The priority mentioned in the embodiment of the present application refers to the priority of the system scheduling process or thread, which can also be called the scheduling priority. Generally speaking, the operating system determines which thread or process is scheduled first based on the scheduling priority to ensure that important tasks are executed in a timely manner. Different threads have different priorities. The embodiment of the present application modifies the UI thread of the process of the second application.
[0148] Exemplarily, the first priority refers to the original priority of the UI thread, and the second priority is the adjusted priority.
[0149] The embodiment of the present application does not specifically limit the specific form of expression of the priority. For example, the value of the first priority is 117, and the value of the second priority is 97. The smaller the value, the higher the priority.
[0150] In step 504, “determine the priority of the UI thread from the first priority to the second priority, wherein the second priority is higher than the first priority” can be expressed as: increasing the scheduling priority of the UI thread.
[0151] Exemplarily, after the priority of the UI thread is increased, it changes from a normal priority to a real-time priority. When the system schedules the threads to run, the priority of a thread with a real-time priority is higher than that of a thread with a normal priority (or non-real-time priority).
[0152] When the process exists, the timing for increasing the priority of the UI thread in the embodiment of the present application can also be considered to be before the interface of the UI thread is generated.
[0153] Step 505: Schedule the UI thread (ie, the UI thread of the process of the second application) based on the second priority.
[0154] Exemplarily, the UI thread of the process of the second application is the thread corresponding to the target applet selected by the user to run in the application. After adjusting the priority of the UI thread of the process of the second application to the second priority, the system preferentially schedules the UI thread of the process of the second application based on the second priority so as to promptly respond to the user's request to use the target applet.
[0155] Optionally, scheduling the UI thread of the process of the second application includes: displaying a user interface corresponding to the Activity instance in the UI thread of the process of the second application, for example, calling a related function to complete drawing of a page and displaying the page to the user.
[0156] In an embodiment of the present application, when it is detected that the first application initiates an operation to start an active interface in the interface, it is determined whether the process of the second application exists, and when the process of the second application exists, it is further determined whether there is an active interface in the process of the second application; when there is no active interface in the process of the second application, the priority of the UI thread of the process of the second application is increased. Compared with the current method of setting the priority of the UI thread only at the oomadjuster update process group, the embodiment of the present application increases the priority of the UI thread of the second application process as soon as the user's intention event to start the mini-program is identified (specifically, when it is detected that the first application initiates an operation to start the active interface in the process of the second application, it is determined that the process of the second application exists and there is no active interface yet), so that the system can give priority to scheduling the UI thread of the second application process, thereby increasing the startup speed of the mini-program and helping to improve the user experience.
[0157] In order to facilitate those skilled in the art to understand the embodiments of the present application, Figure 6 and Figure 7 The timing diagram in Figure 2 is used to illustrate this. Figure 6 The B application is an example of the second application in the previous text, and the A application is an example of the first application in the previous text.
[0158] Figure 6 FIG. 1 shows an example timing diagram of starting the UI thread of application B in an embodiment of the present application. Figure 6 As shown, including:
[0159] Step 1: The process of application A initiates the start of the process of application B.
[0160] Exemplarily, the A application process starts the B application process by using the startService method.
[0161] Step 2: Initialize the process of application B.
[0162] Exemplarily, after receiving the startService initiated by the process of application A, the system service (system_server) calls the startServiceLocked() function to start the B application process for application A.
[0163] It should be understood that the startService and startServiceLocked() functions involved above can refer to the description of the relevant technology, and the embodiments of the present application will not repeat their meanings.
[0164] Step 3: The process of application A starts the Activity in application B.
[0165] In step 3 of the embodiment of the present application, a judgment step is added to the system service (system_server), and the judgment step is used to judge whether the following conditions are met: the process of application B exists, and there is no Activity in the process of application B. If the judgment result is that the process of application B exists, and there is no Activity in the process, then a group can be set at this time. Setting a group specifically means: setting the UI thread of the process of application B (referred to as application B UI thread) as a high-priority thread, or raising the priority of the UI thread. The priority of the UI thread of the embodiment of the present application is higher than that of ordinary threads, and can be scheduled with priority.
[0166] That is to say, the embodiment of the present application advances the step of "setting groups" from step 5 to step 3. "Setting groups" specifically refers to setting the priority groups of the B application UI thread, that is, setting a high priority group for the B application UI thread. High priority can be understood as real-time response priority. A thread with real-time response priority has a higher priority than a thread with non-real-time response priority. Threads with real-time response priority can seize processor resources in real time and can avoid queuing for resources with ordinary threads. Of course, for other threads that also have real-time response priority, they can seize processor resources to execute tasks according to the order of actual runtime.
[0167] While increasing the priority of the UI thread of application B, the UI thread of application B can start the interface in the following ways: calling makeApplication, calling App.onCreat, and calling ActivityStart. ActivityStart represents the official start of the Activity. makeApplication, App.onCreat, and ActivityStart are the functions involved in the process of starting the Activity. For details, please refer to the relevant description, which will not be repeated here.
[0168] Step 4: The process of application A is suspended and enters the background.
[0169] The process of application A is paused and enters the background. For example, the pause can be achieved by calling ActivityPause in the system service (system_server). It can be understood that ActivityPause is a function in the Android Activity startup process, and its explanation can refer to the relevant technology.
[0170] Step 5: The system sets the priority grouping of the UI thread of application B.
[0171] Here, step 5 is the time point for setting the priority grouping of the UI thread of application B in the original process.
[0172] Step 6, B application UI thread starts. Step 6 represents the formal start of the interface of B application UI thread. For example, step 6 can be implemented by calling ActivityStart.
[0173] In the above Figure 6 In the embodiment of the present application, compared with setting the priority grouping of the B application UI thread in step 5, the priority grouping of the B application UI thread is set in step 3. By setting the priority of the B application UI thread in advance, the waiting time of the B application UI thread can be shortened, so that the B application UI thread can be started quickly.
[0174] Figure 7 The figure shows a comparison example of another process of the embodiment of the present application and the existing process. It can be understood by those skilled in the art that Figure 7 The process in this document is only to illustrate the difference between the current application process and the original process, and some detailed steps are appropriately omitted. Figure 7 As shown, including:
[0175] Step 11, the process of application A initiates the process start of application B through the architecture layer (specifically, the system service module in the architecture layer).
[0176] Step 12: The process of application A starts an activity in the process of application B.
[0177] Step 13, when it is detected that the process of application A initiates the behavior of launching the interface, if it is determined that the process of application B exists and there is no Activity in the process of application B, then the grouping is set in advance, that is, the priority of the UI thread of process B is increased.
[0178] Step 14: The priority of the UI thread of process B takes effect.
[0179] Step 15, after the process of application A is suspended and enters the background, the grouping is set.
[0180] Step 16: The priority of the UI thread of process B takes effect.
[0181] Among them, step 13 and step 14 are the method flow of the embodiment of the present application. Step 15 and step 16 are the original method flow. It can be seen that step 13 is a period of time earlier than step 15, so correspondingly, the effective time of the priority will also be advanced accordingly, that is, step 14 will be executed earlier than step 16. For example, step 13 is 114.4ms earlier than step 15, so the effective time point of the priority set by step 13 is 150.4ms earlier than the effective time point of the priority set by step 15.
[0182] Figure 8 A schematic diagram of a specific implementation process of an embodiment of the present application is shown. Figure 8 As shown, the relevant execution modules specifically include: an activity component startup module, an activity component task management service module, a CPU characteristic setting module, an advance setting grouping module, a second activity manager service module and a first activity manager service module. These execution modules can be located at Figure 3 or Figure 4 The architecture layer in .
[0183] Among them, the activity component startup module is a native module in the software architecture, such as the ActivityStarter module in AMS. The activity component task management service module (for example, it can be expressed as HwActivityTaskManagerServiceEx), the CPU feature setting module (for example, it can be expressed as CpuFeature), the advance grouping module (for example, it can be expressed as AppActivityAdvanceSched), the second activity manager service module (for example, it can be expressed as HwActivityManagerServiceEx) and the first activity manager service module (for example, it can be expressed as Activity ManagerService) are new modules in the embodiment of the present application and can be located in Figure 4 For example, the grouping module can be set up in advance to correspond to Figure 4 The CPU feature setting module can correspond to the setting grouping module and the verification module in the architecture layer. Figure 4 Configuration management module and feature switch module in .
[0184] Exemplarily, the activity component task management service module can be expressed as;
[0185] Step 600: The active component starts the module to initialize the system.
[0186] Step 601, the CPU feature setting module subscribes to features while initializing the system, for example, enabling the advance grouping module to implement the thread management method of the embodiment of the present application.
[0187] The CPU feature setting module is used to implement the subscription feature to enable the method for managing threads in the embodiment of the present application.
[0188] Step 602: The activity component startup module executes the Activity startup process.
[0189] Step 603: The activity component startup module notifies the activity component task management service module to initiate an Activity process.
[0190] Step 604: the activity component startup module notifies the activity component to initiate an Activity process to the CPU characteristic setting module.
[0191] Step 605: The CPU feature setting module initiates an Activity status check process.
[0192] Step 606, the grouping module is set in advance to obtain the process status of the second application. For example, the process status of the second application is obtained through the second activity manager service module and the first activity manager service module. The process status of the second application refers to whether the process of the second application exists and whether there is an active interface in the process of the second application.
[0193] For example, the pre-set grouping module may query the second activity manager service module by calling the function getProcessRecordlockedEx; the second activity manager service module may query the first activity manager service module by calling the function getProcessRecordlocked.
[0194] Step 607: Return the process status of the second application to the advance grouping module.
[0195] Step 608: When the advance grouping module determines that the process of the second application already exists and there is no Activity in the process of the second application, the priority of the UI thread of the process of the second application is increased. For related explanations, please refer to the above description.
[0196] It should be understood that Figure 6 The illustrated process is only for the convenience of understanding by those skilled in the art and does not constitute a limitation on the embodiments of the present application.
[0197] For ease of understanding, the following will be combined Figures 9 to 13 Describe the scenarios to which the method for managing threads according to an embodiment of the present application is applicable.
[0198] The embodiment of the present application does not specifically limit the type of application (first application or second application).
[0199] Optionally, in some embodiments, the application may be a third-party application; the UI thread of the second application's process may be a UI thread that needs to respond after the user clicks on a function or application in the third-party application. For example, the first application is Alipay, and the second application is a small program in Alipay. The user clicks on the small program in the Alipay application (started by the startService method), the user clicks on the small program in the WeChat application (started by the startService method), the user opens word / PDF / PPT and other files in the WeChat application, the user clicks on the member purchase item in a certain application, the user pulls up the Alipay verification interface when logging into the Taobao account, and so on. The following is combined with Fig. 9 and Fig.10 The application scenario in is described below.
[0200] Fig. 9 An example diagram of an application scenario in which the method for managing threads according to an embodiment of the present application is applicable is shown. Fig. 9 The interface shown in (1) is similar to Figure 1 The interface shown in (1) is the same as that shown in (1). For related descriptions, please refer to the previous text. Fig. 9 After you open the sports app in the Alipay application shown in (1), the interface will quickly display the following Fig. 9 The interface shown in (2) presents the details interface of the sports applet to the user, shortening the startup time and improving the user experience.
[0201] It should be understood that Fig. 9 In the description, the Alipay program is used as an example, and the embodiments of the present application are not limited thereto. In fact, the embodiments of the present application can also be applied to other third-party applications.
[0202] Fig.10 Another example diagram of an application scenario to which the method for managing threads in an embodiment of the present application is applicable is shown. For example, the first application is a WeChat application, and the process of the second application is the process corresponding to the "Honor Mall" in the WeChat application. Fig.10 As shown in (1), the user slides down the screen in the WeChat interface to enter the WeChat app interface, such as Fig.10 The interface shown in (2).
[0203] like Fig.10 As shown in (2), the interface includes a mini-program search box, application icons of recently used mini-programs (such as Honor Mall), etc. It can be understood that Fig.10 (2) can also display the article, video, live broadcast, etc. that the user has just watched (not shown in the figure). When the user clicks the icon of the recently used mini program "Honor Mall", the interface displays as follows Fig.10 As shown in (3). Fig.10 As shown in (3), the mobile phone will display the UI interface of the mini program "Honor Mall" more quickly.
[0204] Optionally, in some embodiments, the first application may be a Honor self-developed application; the second application may be a function or application in the Honor self-developed application that the user clicks on. For example, the user clicks on the quick service engine on the negative first screen to open the application, the user clicks on a web link on the negative first screen to enter the web page details page, the user clicks on "My Service" on the negative first screen to enter the settings page, the user clicks on a certain setting function on the settings page of "My Service" on the negative first screen, the user logs in to the Honor account, the notification window pops up automatically when the user clicks on the game function, etc. The following is combined with Fig.11 The application scenario in is described below.
[0205] Fig.11 A diagram showing another example of an application scenario to which the method for managing threads according to an embodiment of the present application is applicable. Fig.11 (1) shows the main interface (or main screen) of the mobile phone. Fig.11 As shown in (1), the desktop displays icons of some applications (e.g., application 1 to application 8). When the user slides the screen to the right on the main interface of the mobile phone, the mobile phone enters the negative one screen. For example, the interface of the negative one screen is as follows Fig.11 The interface shown in (2).
[0206] Understandably, Fig.11 The gesture operation position of sliding the screen to the right shown in (1) is only an exemplary description, and the embodiments of the present application are not limited thereto. In fact, the user can Fig.11 Slide the screen to the right from any position shown in (1) or use other methods to enter the negative one screen page.
[0207] For example, Fig.11 As shown in (2), the negative one screen interface includes a control 201. The control 201 is the setting entry for the user to enter the "my" negative one screen.
[0208] For example, Fig.11 As shown in (2), area 202 in the negative one screen interface is used to display quick functions added by the user, including: scan code, payment code, latest photos, frequently used contacts, etc.
[0209] For example, Fig.11 As shown in (2), the negative one screen interface includes an application usage statistics card 203, a today's hot spots card 204, a schedule card 205 and a sports health card 206.
[0210] It can be understood that the negative one screen can be used to display cards, notification messages, etc. of user-common service functions or applications. Fig.11 The content of the negative one screen shown in (2) is only an example, and the embodiments of the present application are not limited to this.
[0211] It can also be understood that users can add shortcuts, commonly used applications, links, applets, etc. in the negative one screen interface based on their needs.
[0212] for Fig.11 In the card or control shown in (2), when the user clicks on a card or control, the interface can jump to the related interface. Through the embodiment of the present application, when the user clicks on a card or control, the UI thread related to it is given a higher priority, so that the user's needs are responded to more quickly, so that the related interface is presented to the user more quickly, thereby improving the user experience.
[0213] Take the example of a user clicking on the control 201. When the user clicks on the "My" control 201, the interface is displayed as follows: Fig.11 In the embodiment of the present application, when it is detected that the UI thread corresponding to the "My" control already exists and there is no interface for it, the priority of the UI thread corresponding to the "My" control can be increased so that the "My" interface can be displayed more quickly, that is, Fig.11 The interface shown in (3).
[0214] like Fig.11 As shown in (3), the "My" interface includes relevant management controls for the negative first screen. For example, drop-down greeting settings, search settings, service direct switch options (the figure shows the on state), discovery settings, information settings, interest preference settings, personal information settings, settings, etc. The drop-down greeting settings are used to set the greeting displayed to the user when the negative first screen page is dropped down.
[0215] Optionally, in some embodiments, the first application may be a system application; the UI thread of the second application's process may be a UI thread that automatically triggers a function in the application or that needs to respond after the application is run when the system application is run.
[0216] For example, the embodiment of the present application is applicable to the TOP50 application desktop cold start scenario. The application scenario specifically refers to: judging whether the application is a high-frequency application (i.e., the top 50) based on the number of user usage statistics; if it is a TOP50 application, then the technical solution of the embodiment of the present application is applicable.
[0217] Exemplarily, the embodiments of the present application are applicable to the warm start scenario of some applications. This application scenario refers to: when the application is started, the process of the application already exists in the background, but the Activity is recycled due to insufficient memory. Common warm start scenarios usually include the following two: (1) The user presses the return key continuously to exit the application and finally restarts the application; (2) The system recycles the memory of the application and finally restarts the application.
[0218] For example, the embodiment of the present application is applicable to pop-up windows of some applications requesting certain permissions. The permissions include but are not limited to: recorder permission, sharing permission, location permission, photo taking permission, sharing permission, etc.
[0219] For example, when a user connects a Bluetooth headset, the electronic device will automatically pop up a window requesting relevant permissions requested by the Bluetooth headset.
[0220] For example, the present application embodiment is applicable to Honor sharing pop-up windows, etc. Fig.12 and Fig.13 The application scenario in is described below.
[0221] Fig.12 A diagram showing another example of an application scenario to which the method for managing threads according to an embodiment of the present application is applicable. Fig.12 (1) shows the browsing interface of a photo in the gallery. Fig.12 As shown in (1), the interface includes a sharing control 1201.
[0222] When the user clicks the share control 1201, the interface displays as follows Fig.12 The interface shown in (2) is shown in the figure. Fig.12 In the interface shown in (2), the Honor sharing control 1202 is displayed.
[0223] Understandably, Fig.12 In (1), in addition to the sharing control 1201, other functional controls may also be included. For example, Fig.12 (1) also shows: a collection control for collecting photos; an edit control for editing photos; a delete control for deleting photos; and more controls.
[0224] When the user clicks the Honor share control 1202, the interface displays as follows Fig.12 The interface shown in (3) is shown in the figure. Fig.12 In the interface shown in (3), the welcome window 1203 of the Honor Sharing interface is displayed. Fig.12In the example, the UI thread of the B application process is the UI thread corresponding to the Honor Share window 1203. The Honor Share window 1203 may include content about Honor Share displayed to the user. Optionally, the Honor Share window 1203 may also include an Agree and Cancel button for the user to select.
[0225] Fig.13 Another example diagram of an application scenario in which the method for managing threads in an embodiment of the present application is applicable is shown. When the system recognizes that the mobile phone has not opened the cloud space, a window 1301 may be automatically popped up to prompt the user whether to open the cloud space. Fig.13 In the example, the UI thread of the process of the second application is the UI thread corresponding to the opened cloud space.
[0226] It should be understood that Figures 9 to 13 The application scenarios shown in the figure are merely exemplary descriptions, and the embodiments of the present application are not limited thereto.
[0227] Optionally, the technical solution of the embodiment of the present application can also open the foreground behavior interface capability to third-party applications, so that the third-party applications can provide feedback to the system side on processes or threads that need to be processed first based on business scenarios.
[0228] Combination of the above Figures 1 to 13 , describes in detail the method for managing threads provided by the embodiment of the present application. Fig.14 It should be understood that the thread management device of the embodiment of the present application can execute the various thread management methods of the aforementioned embodiment of the present application, that is, the specific working process of the following various products can refer to the corresponding process in the aforementioned method embodiment.
[0229] Fig.14 1 is a schematic block diagram of a thread management apparatus 1400 according to an embodiment of the present application. It should be understood that the apparatus 1400 may execute Figures 5 to 13 The method of managing threads is shown.
[0230] like Fig.14 As shown, the thread management device 1400 includes: an input unit 1410, a processing unit 1420, and a display unit 1430. The input unit 1410 and the display unit 1430 are optional. In a possible example, the device 1400 may be an electronic device, such as a mobile phone.
[0231] In some embodiments, the processing unit 1420 is used to determine whether the process of the first application exists when it is detected that the process of the second application initiates an operation to start an active interface in the process of the second application; when the process of the second application exists, determine whether the active interface exists in the process of the second application; when the active interface does not currently exist in the process of the second application, determine the priority of the user interface UI thread of the process of the second application from a first priority to a second priority, the second priority being higher than the first priority; and based on the second priority, schedule the UI thread of the process of the second application.
[0232] Optionally, as an embodiment, the processing unit 1420 is also used to detect that the process of the first application triggers the process of the second application in an inactive manner before detecting that the process of the first application initiates an operation of starting an active interface in the process of the second application.
[0233] Optionally, as an embodiment, the processing unit 1420 is used to detect that the process of the first application triggers the process of the second application in an inactive manner, including:
[0234] It is detected that the process of the first application starts the process of the second application through the system's startup service, broadcast or content provider.
[0235] Optionally, as an embodiment, the processing unit 1420 is configured to detect that the process of the first application triggers the process of the second application, including:
[0236] In response to detecting a first operation of the user inputted by the input unit 1410 , the process of the second application is triggered by the process of the first application, wherein the first operation is an operation of clicking an application icon corresponding to a target applet.
[0237] Optionally, as an embodiment, the first application is a third-party application, and the UI thread of the process of the second application is the UI thread of the target applet in the first application.
[0238] Optionally, as an embodiment, the first application is a system application, and the UI thread of the process of the second application is a UI thread in the system application.
[0239] Optionally, as an embodiment, the processing unit 1420 is configured to determine whether the activity interface exists in the process of the second application program, including:
[0240] By identifying whether the process of the second application includes a task stack, it is determined whether an Activity instance currently exists in the process of the second application.
[0241] Optionally, as an embodiment, the processing unit 1420 schedules the UI thread, including: displaying the activity interface of the UI thread of the second application through the display unit 1430.
[0242] In a possible example, the processing unit 1420 may be implemented by a processor or a processing unit. It should be understood that the above-mentioned device 1400 is embodied in the form of a functional unit. The term "unit" here may be implemented in the form of software and / or hardware, and the embodiment of the present application does not specifically limit this. The display unit 1430 may be implemented by a display screen.
[0243] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two to implement the above functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (such as a shared processor, a dedicated processor, or a group processor, etc.) that executes one or more software or firmware programs and a memory, an integrated logic circuit, and / or other suitable devices that can provide the above functions. In a simple embodiment, a person skilled in the art can imagine that the device 1400 can be used Figure 2 The form shown.
[0244] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software 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.
[0245] The present application also provides a computer program product, which, when executed by a processor, implements the method described in any method embodiment of the present application.
[0246] The computer program product can be stored in a memory, and is finally converted into an executable target file that can be executed by a processor after preprocessing, compiling, assembling and linking.
[0247] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a computer, the method described in any method embodiment of the present application is implemented. The computer program can be a high-level language program or an executable target program.
[0248] The computer-readable storage medium may be a volatile memory or a nonvolatile memory, or may include both a volatile memory and a nonvolatile memory. The nonvolatile memory may be a read-only memory (ROM), a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may 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 bus RAM (DR RAM).
[0249] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software 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.
[0250] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0251] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0252] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0253] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0254] 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.
[0255] It should be understood that in the various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0256] In addition, the terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. For example, A / B can mean A or B.
[0257] The terms (or numbers) "first", "second", ..., etc. that appear in the embodiments of the present application are only used for descriptive purposes, that is, only to distinguish different objects, such as different "priorities", etc., and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first", "second", ..., etc. may explicitly or implicitly include one or more features. In the description of the embodiments of the present application, "at least one (item)" refers to one or more. "Multiple" means two or more. "At least one of the following (items)" or similar expressions thereof refers to any combination of these items, including any combination of a single (item) or a plurality of (items).
[0258] For example, the meaning of the expression similar to "the item includes at least one of the following: A, B, and C" in the embodiments of the present application, unless otherwise specified, generally means that the item can be any one of the following: A; B; C; A and B; A and C; B and C; A, B and C; A and A; A, A and A; A, A and B; A, A and C, A, B and B; A, C and C; B and B, B, B and B, B, B and C, C and C; C, C and C, and other combinations of A, B and C. The above is an example of three elements, A, B and C, to illustrate the optional items of the item. When it is expressed as "the item includes at least one of the following: A, B, ..., and X", that is, when there are more elements in the expression, the items that can be applied to the item can also be obtained according to the above rules.
[0259] In short, the above is only a preferred embodiment of the technical solution of this application, and is not intended to limit the protection scope of this application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application should be included in the protection scope of this application.
Claims
1. A method for managing threads, characterized in that: include: When detecting that the process of the first application initiates an operation of starting the activity interface in the process of the second application, determining whether the process of the second application exists; When the process of the second application exists, determining whether the active interface exists in the process of the second application; When the active interface does not currently exist in the process of the second application, determining the priority of the user interface UI thread of the process of the second application from the first priority to the second priority, where the second priority is higher than the first priority; Based on the second priority, the UI thread of the process of the second application is scheduled.
2. The method according to claim 1, characterized in that Before the process of detecting that the first application program initiates an operation of starting the activity interface in the process of the second application program, the method further includes: It is detected that the process of the first application triggers the process of the second application.
3. The method according to claim 2, characterized in that The detecting that the process of the first application triggers the process of the second application includes: It is detected that the process of the first application starts the process of the second application through the system's startup service, broadcast or content provider.
4. The method according to claim 2 or 3, characterized in that: The detecting that the process of the first application triggers the process of the second application includes: In response to detecting a first operation of the user, the process of the second application is triggered by the process of the first application, where the first operation is an operation of clicking an application icon corresponding to a target applet.
5. The method according to claim 4, characterized in that The first application is a third-party application, and the UI thread of the process of the second application is the UI thread of the target applet in the first application.
6. The method according to any one of claims 1 to 3, characterized in that The first application is a system application, and the UI thread of the process of the second application is a UI thread in the system application.
7. The method according to any one of claims 1 to 6, characterized in that The determining whether the active interface exists in the process of the second application program includes: By identifying whether the process of the second application includes a task stack, it is determined whether an Activity instance currently exists in the process of the second application.
8. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the processor and the memory are coupled, and the memory is used to store a computer program. When the computer program is executed by the processor, the electronic device executes the method according to any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 7.
10. A chip, characterized in that: The method comprises a processor, and when the processor executes instructions, the processor performs the method according to any one of claims 1 to 7.
