Event processing method, electronic equipment, storage medium and program product
By introducing a multi-event queue management mechanism in the application, distinguishing between high- and low-priority events and promptly interrupting low-priority processing, the problem of application freezes caused by blocking low-priority events is solved, and the user experience is improved.
Patent Information
- Application Number
- CN202510453102.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2025-09-19
AI Technical Summary
During application operation, low-priority events take too long to be processed, which blocks high-priority events and prevents them from being processed in a timely manner. This causes application lag and affects user experience.
A multi-event queue management mechanism is adopted to distinguish between high-priority and low-priority event queues. By detecting whether there are high-priority events that need to be processed in a timely manner, the processing of low-priority events is interrupted and high-priority events are processed first, ensuring that high-priority events can be responded to in a timely manner.
It effectively reduces the probability of application jams, improves user experience, ensures that high-priority events can be processed in a timely manner, and avoids jams caused by blocking low-priority events.
Smart Images

Figure CN120670101A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to an event processing method, electronic device, storage medium, and program product. Background Art
[0002] To meet consumers' growing functional demands, technicians have developed many different types of applications (APPs). Users can install a variety of applications in their electronic products.
[0003] In real-world scenarios, apps may experience lag while running. Generally, lag occurs when the event currently being processed by the app takes too long, causing a backlog / blocking of other pending events. This manifests as slow or unresponsive app response, or lag. Therefore, managing pending events is essential to avoid lag. Summary of the Invention
[0004] The embodiments of the present application provide an event processing method, electronic device, storage medium, and program product, which can avoid application lag as much as possible and improve user experience.
[0005] In a first aspect, an event processing method is provided for an electronic device. The electronic device includes a first application, and the event queue of the first application includes a first queue and a second queue. The first queue and the second queue are respectively used to store pending events of the first application, and the priority of the first queue is higher than the priority of the second queue. The method includes: the electronic device processes a first event in the second queue; during the processing of the first event, detecting whether a second event that requires prompt processing exists in the first queue; if the presence of the second event that requires prompt processing is detected in the first queue, interrupting the processing of the first event and processing the second event.
[0006] Therefore, in the embodiment of the present application, the pending events of the application are divided into high priority and low priority, and low priority events can be interrupted by high priority events, thereby ensuring that high priority events can be processed in a timely manner. In this way, the probability of application freezing can be reduced and the user experience can be improved.
[0007] In one possible design, processing the first event in the second queue includes: a first application processes the first event in the second queue; detecting whether there is a second event in the first queue that needs to be processed in a timely manner includes: the first application detects whether there is a second event in the first queue that needs to be processed in a timely manner; interrupting the processing of the first event includes: the first application interrupts the processing of the first event. Wherein, the first application processes the first event in the second queue, which may include: the first application processes the first event in the second queue according to the storage address of the second queue. The first application detects whether there is a second event in the first queue that needs to be processed in a timely manner, which may include: the first application detects whether there is a second event in the first queue that needs to be processed in a timely manner according to the storage address of the first queue. Wherein, the storage address of the first queue and / or the storage address of the second queue are obtained by the first application through the first interface. The first interface is an interface provided by the operating system of the electronic device.
[0008] In one possible design, the second event is an event that requires feedback to the user, and / or the waiting time of the second event in the first queue exceeds the first time. Therefore, in this way, the electronic device can promptly process events that require feedback to the user and / or events with long waiting times, avoiding event accumulation / blocking and improving the smoothness of application operation. Moreover, because events that require feedback to the user are handled promptly, the user will not feel that the application is responding slowly or lags, which helps to improve the user experience.
[0009] In one possible design, before detecting whether there is a second event in the first queue that needs to be processed in a timely manner, the method further includes: determining that the total processing time of the first event exceeds the second duration, and / or that the processed duration of the first event exceeds the third duration. Therefore, in an embodiment of the present application, if the currently processed event is a long-time event, the currently processed event is interrupted and other events (events that need to be processed in a timely manner) are processed in a timely manner. In this way, application jams can be avoided as much as possible and the user experience can be improved.
[0010] In one possible design, the method further includes generating a third event based on the unprocessed portion of the first event, and the third event is placed in the first queue or the second queue to await processing. Thus, in this manner, the unprocessed portion of the first event can continue to be processed, ensuring that the first event can be fully processed.
[0011] In one possible design, when the third event enters the second queue, the third event is placed at the head of the second queue. Therefore, in this way, the unprocessed portion of the first event can be processed as quickly as possible, avoiding a long processing time interval between the processed and unprocessed portions of the first event.
[0012] In one possible design, the method further includes: processing the third event after the second event is processed; during the processing of the third event, detecting whether there is a fourth event in the first queue that needs to be processed in a timely manner; if it is detected that there is a fourth event in the first queue that needs to be processed in a timely manner, interrupting the processing of the third event and processing the fourth event. Therefore, in an embodiment of the present application, an event (for example, the first event) can be interrupted once or multiple times to ensure that other events (events that need to be processed in a timely manner) can be processed in a timely manner.
[0013] In one possible design, the first event includes N sub-events, where N is an integer greater than or equal to 2. During the processing of the first event, detecting whether there is a second event in the first queue that needs to be processed in a timely manner includes: performing a detection step once in the processing gap between every two adjacent sub-events in the N sub-events, the detection step being used to detect whether there is a second event in the first queue that needs to be processed in a timely manner, and the processing gap includes the time period from the end time of the processing of the previous sub-event to the start time of the processing of the next sub-event. Therefore, in an embodiment of the present application, in the processing gap between two adjacent sub-events, it is detected whether there is an event that needs to be processed in a timely manner. In this way, on the one hand, it does not affect the processing of each sub-event, and on the other hand, it is possible to detect in a timely manner whether there is an event that needs to be processed in a timely manner.
[0014] In one possible design, the N sub-events are the N sub-events obtained by dividing the first event according to function or duration; wherein, each sub-event in the N sub-events obtained by functional division is used to implement a different function, and the processing time of each sub-event in the N sub-events obtained by duration is T / N, where T is the total processing time of the first event. Therefore, in an embodiment of the present application, an event can be divided into multiple sub-events, and in the processing gap between two adjacent sub-events, it is detected whether there is an event that needs to be processed in a timely manner. In this way, on the one hand, it does not affect the processing of each sub-event, and on the other hand, it can be detected in a timely manner whether there is an event that needs to be processed in a timely manner.
[0015] In one possible design, the event queue also includes a third queue, and the priority of the third queue is higher than the priority of the first queue. The method also includes: during the processing of the second event, detecting whether there is a fifth event in the third queue that needs to be processed in a timely manner; if it is detected that there is a fifth event in the third queue that needs to be processed in a timely manner, interrupting the processing of the second event and processing the fifth event. Therefore, in an embodiment of the present application, a low-priority event can be interrupted by a high-priority event, and the high-priority event can be interrupted by an even higher-priority event. In other words, the higher the priority of the event, the more timely it can be processed. In this way, the probability of application freezes can be reduced and the user experience can be improved.
[0016] In one possible design, the event queue also includes a fourth queue, and the priority of the fourth queue is higher than that of the first queue. During the processing of the first event, it is detected whether there is a second event in the first queue that needs to be processed in a timely manner, including: during the processing of the first event, it is detected whether there is a sixth event in the fourth queue that needs to be processed in a timely manner; if there is no sixth event in the fourth queue that needs to be processed in a timely manner, then it is detected whether there is a second event in the first queue that needs to be processed in a timely manner. Therefore, in this way, it is possible to detect whether there are events that need to be processed in a timely manner in each queue in order of queue priority from high to low. The higher the priority of the event, the more likely it is to be processed in a timely manner. In this way, the probability of application freezes can be reduced and the user experience can be improved.
[0017] In one possible design, the method further includes: if there is a sixth event in the fourth queue that needs to be processed in a timely manner, then interrupting the first event and processing the sixth event; after the sixth event is processed, detecting whether there is a second event in the first queue that needs to be processed in a timely manner; if it is detected that there is a second event in the first queue that needs to be processed in a timely manner, then processing the second event. Therefore, in this way, it is possible to detect whether there are events that need to be processed in a timely manner in each queue in order of queue priority from high to low. The higher the priority of the event, the more likely it is to be processed in a timely manner. In this way, the probability of application freezes can be reduced and the user experience can be improved.
[0018] In one possible design, processing the second event includes processing the second event based on the processed portion of the first event. Therefore, in an embodiment of the present application, a low-priority event can be interrupted by a high-priority event, and when processing a high-priority event, the high-priority event can be processed based on the processed portion of the low-priority event. In this way, the processed portion of the low-priority event can be involved in the operation of the application in advance, which helps to improve the smoothness of the application operation.
[0019] In one possible design, the first event is used to obtain display elements within the target interface of the first application, the processed portion of the first event includes the obtained first display element, the second event is an interface refresh event, and the processing of the second event based on the processed portion of the first event includes: displaying the target interface based on the first display element, wherein the target interface includes the first display element. Therefore, in this way, the display elements within the target interface are obtained in batches, and when the electronic device displays the target interface, the obtained display elements can be displayed within the target interface, without having to wait until all display elements are obtained before displaying the target interface, thereby shortening the user's waiting time and improving the user experience.
[0020] In one possible design, the method further includes: after the second event is processed, processing a seventh event, the seventh event includes the unprocessed portion of the first event, and the seventh event is used to obtain the second display element in the target interface; during the processing of the seventh event, it is detected that there is an eighth event in the first queue that needs to be processed in a timely manner, and the eighth event is an interface refresh event; if the processing time of the seventh event is less than a threshold, then after processing the seventh event, the eighth event is processed according to the processing result of the seventh event. Therefore, in this way, the display elements in the target interface are obtained in batches, and each time a part of the display elements is obtained, the part of the display elements is displayed, and there is no need to wait until all the display elements are obtained before displaying the target interface, which shortens the user waiting time and improves the user experience.
[0021] In one possible design, the processing result of the seventh event includes the acquired second display element, and processing the eighth event based on the processing result of the seventh event includes refreshing the target interface based on the second display element, wherein the target interface includes the second display element. Therefore, in this way, when the electronic device displays the target interface, the display elements in the target interface are gradually displayed in batches, shortening the user's waiting time and improving the user experience.
[0022] In one possible design, the method further includes: if the processing time of the seventh event is greater than or equal to the threshold, interrupting the processing of the seventh event, and processing the eighth event based on the processed portion of the seventh event. Therefore, in this way, the display elements in the target interface are acquired in batches, and each time a portion of the display elements is acquired, the portion of the display elements is displayed, without having to wait until all the display elements are acquired before displaying the target interface, thereby shortening the user's waiting time and improving the user experience.
[0023] In one possible design, the first event is used to obtain the display elements within the target interface from a local database or server. Therefore, in an embodiment of the present application, if the electronic device needs to display the target interface and the display elements within the target interface need to be obtained from a local database or server, there is no need to wait until all the display elements are obtained before displaying the target interface. Instead, the display elements within the target interface can be obtained in batches, and each time a portion of the display elements is obtained, the portion of the display elements is displayed, thereby shortening the user's waiting time and improving the user experience.
[0024] In a second aspect, an electronic device is also provided for executing the method provided in the first aspect.
[0025] In a third aspect, a computer-readable storage medium is further provided, wherein the computer-readable storage medium is used to store a computer program. When the computer program is run on a computer, the computer is caused to execute the method provided in the first aspect above.
[0026] In a fourth aspect, a computer program product is also provided, comprising a computer program, which, when run on a computer, enables the computer to execute the method provided in the first aspect above.
[0027] In a fifth aspect, a chip is also provided, wherein the chip is used to execute the method provided in the first aspect above.
[0028] For the technical effects that can be achieved in the above-mentioned second to fifth aspects, please refer to the description of the technical effects that can be achieved by the corresponding design scheme in the above-mentioned first aspect, and this application will not repeat them here. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A schematic diagram of an event queue of an application provided in one embodiment of the present application;
[0030] Figures 2A to 2B An example diagram of a scenario in which an application freezes, provided in an embodiment of the present application;
[0031] Figures 3A to 3B This is an example diagram of another scenario of application freeze provided in an embodiment of the present application;
[0032] Figure 4 Another schematic diagram of an event queue of an application provided in an embodiment of the present application;
[0033] Figures 5A to 5B A schematic diagram of a first application scenario provided in an embodiment of the present application;
[0034] Figures 6A to 6B A schematic diagram of a second application scenario provided in an embodiment of the present application;
[0035] Figure 7 A schematic diagram of an event queue of a first application provided in an embodiment of the present application;
[0036] Figure 8 A flowchart of an event processing method provided in one embodiment of the present application;
[0037] Figure 9 Another flowchart of an event processing method provided in one embodiment of the present application;
[0038] Figure 10 Another schematic diagram of an event queue of a first application provided in an embodiment of the present application;
[0039] Figure 11 Another flowchart of an event processing method provided in an embodiment of the present application;
[0040] Figure 12 A schematic structural diagram of an electronic device provided in one embodiment of the present application;
[0041] Figure 13 Another structural diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0042] Below, some terms used in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0043] The at least one involved in the embodiments of the present application includes one or more; wherein, more means greater than or equal to two. In addition, it should be understood that, in the description of this specification, words such as "first" and "second" are only used for the purpose of distinguishing the description, and cannot be understood as expressing or implying relative importance, nor can they be understood as expressing or implying order. For example, the first queue and the second queue do not represent the importance of the two or the order of the two, but are only for distinguishing the description. In the embodiments of the present application, "and / or" is only a description of the association relationship, indicating that there can be three relationships. For example, A and / or B can represent: 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 previous and next associated objects are in an "or" relationship.
[0044] The directional terms mentioned in the embodiments of the present application, such as "up", "down", "left", "right", "inside", "outside", etc., are only references to the directions in the drawings. Therefore, the directional terms used are for better and clearer explanation and understanding of the embodiments of the present application, rather than indicating or implying that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the embodiments of the present application.
[0045] References to "one embodiment," "in some examples," or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the specification. Thus, phrases such as "in some examples," "in one embodiment," "in some other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0046] The technical solutions provided in the embodiments of the present application are described below with reference to the accompanying drawings.
[0047] Electronic devices include a wide variety of applications. These applications can be launched and run based on user actions. It should be noted that the application's running process can be understood as the process by which the application continuously processes events and responds. Events that require application processing are called pending events for the application. To avoid confusion, an event management mechanism can be used to manage the application's pending events, as the number of pending events for an application is relatively large.
[0048] One possible management method is to introduce an event queue and manage the pending events of the application through the event queue. The event queue meets the first-in-first-out (FIFO) principle. For example, the pending events of the application enter the event queue in the order of generation time and are sorted and wait for processing. Then, the application takes out the pending events from the event queue according to the first-in-first-out principle and processes the pending events. The introduction of the event queue can make the event processing process of the application proceed in an orderly manner. However, with the continuous improvement of the business, the number of pending events of the application increases. Considering that a single event queue easily causes the pending events to pile up / block, it is difficult to meet the demand. Therefore, the embodiment of the present application adopts a management mechanism of multiple event queues, that is, one application corresponds to multiple event queues.
[0049] For ease of management, when an application corresponds to multiple event queues, different event queues need to be distinguished. One possible way to distinguish them is to have different priorities for each event queue. For example, see Figure 1 The application's event queues include Queue 1 and Queue 2. Queue 1 has a higher priority than Queue 2. That is, Queue 1 stores higher-priority pending events, while Queue 2 stores lower-priority pending events. Both Queue 1 and Queue 2 adhere to the first-in, first-out principle.
[0050] In actual usage scenarios, pending events in a high-priority queue (for example, queue 1) may be blocked by low-priority events and cannot be processed in a timely manner.
[0051] For example, Figure 1 In the example, assuming that event 1 enters queue 2 first, the application will process event 1 first. During the processing of event 1, event 2 enters queue 1. Therefore, after the application finishes processing event 1, it processes event 2. In other words, Figure 1 The event processing order used in the application is: process event 1 first, then process event 2. It should be noted that Figure 1 The arrows used to indicate the order of event processing (dashed arrows in the figure) point from the left to the right, indicating that the events on the right are executed before the events on the left. Figure 1 Above the dotted arrow, since event 1 is on the right side of event 2, the event processing order is to process event 1 first and then event 2. The principles of the subsequent figures are the same. Figure 1 It is understandable that if the processing of event 1 takes a long time, event 2 will have to wait for a long time. If there are other high-priority events after event 2 ( Figure 1 (not shown), these high-priority events will be blocked because the processing of event 1 takes too long. Assuming that high-priority events are events that require feedback to the user (for example, interface refresh events) or events that are perceptible to the user, high-priority events are blocked, that is, they cannot feedback information to the user in time, and the resulting external manifestation is slow or no response of the application, that is, application freeze. Therefore, through Figure 1 It can be seen that the reason for the application lag is that the processing of low-priority events takes too long and cannot be interrupted, resulting in the high-priority queue being blocked and unable to be processed in time.
[0052] For ease of understanding, the following examples illustrate several scenarios of application jams caused by the above reasons. As mentioned above, the application's response speed is slow, causing the user to feel a sense of waiting, and this sense of waiting is seen by the user as application jams. Among them, one manifestation of the slow response speed of the application is that the display interface of the application is updated slowly. For example, after the user clicks on a control in the current interface, it is necessary to wait for a certain period of time before the target interface (the interface that the control is used to open) is displayed, which gives the user the feeling of application jams. Among them, the target interface appears slowly because the processing of the aforementioned low-priority events takes too long and cannot be interrupted, resulting in the blocking of the high-priority queue. The following is explained with two specific examples. The target interfaces in these two examples are different.
[0053] Example 1: Application interface switching scenario
[0054] For example, Figure 2A(a) The electronic device displays the main interface of the settings application, which includes the option 200 for notifications and status bar. Optionally, a brief introduction to option 200 may also be displayed, such as "which applications' messages are allowed to be displayed in the status bar". After the electronic device receives the operation for option 200, it displays the following information: Figure 2A (b) The interface displays a prompt message to prompt the user to wait. Optionally, the prompt message may be present or absent, without limitation. Figure 2A (c) interface, which includes information about each application in the electronic device (for example, the application icon and / or name) and a switch control corresponding to each application, which is used to turn on or off the status bar notification function of the application (that is, whether the application message is displayed in the status bar). Figure 2A The interface shown in (c) is called the target interface. Figure 2A It can be seen that after the electronic device receives the operation for opening the target interface, it needs to wait for a certain period of time before the target interface is displayed. From the user's perspective, this feeling of waiting is application lag.
[0055] The following is passed Figure 2B ,illustrate Figure 2A The specific reason why the target interface of the application is stuck is set in .
[0056] After the settings application receives an operation for instructing to open the target interface (for example, the user clicks option 200), it determines that the display elements in the target interface (for example, the information of each application and whether each application has enabled the status bar notification function) need to be obtained through database access, and then generates event 1. Event 1 is a database access event, which is used to obtain the information of each application and whether each application has enabled the status bar notification function from the database. In other words, event 1 is used to obtain the display elements in the target interface. Event 1 is thrown into the event queue of the settings application, such as Figure 2B (a) Since event 1 (i.e., the database access event) has a lower priority, event 1 enters queue 2. The application is configured to remove event 1 from queue 2 and process event 1, namely, by accessing the database to obtain information about each application and whether the status bar notification function is enabled for each application, that is, to obtain display elements within the target interface. Optionally, the database can be a local database of the electronic device or a cloud database, and the database includes information about each application in the electronic device and whether the status bar notification function is enabled for each application.
[0057] Before event 1 is processed, the settings application will send an interface update request to the operating system, indicating that the settings application has an interface update requirement. In response to the settings application's interface update request, the operating system posts an interface refresh event to the settings application's event queue to instruct it to refresh the interface. For example, the interface refresh event can be a frame synchronization event of the display screen, such as a vertical synchronization (Vsync) event. Figure 2B (b), since the Vsync event is of high priority, the Vsync event enters queue 1. It should be noted that although the Vsync event is a high priority event, since event 1 (i.e., the database access event) has not been processed yet, it is necessary to wait until event 1 is processed before the Vsync event can be processed. As mentioned above, event 1 is used to access the database to obtain information about each application and whether each application has enabled the status bar notification function, so the processing of event 1 takes a long time, and the Vsync event needs to wait for a long time. As mentioned above, the Vsync event is an interface refresh event. If the Vsync event cannot be processed in time, the target interface cannot be updated in time. Therefore, Figure 2A (b) shows the waiting scene.
[0058] like Figure 2B (c) After event 1 is processed, the application is set to take out the Vsync event from queue 1 and process the Vsync event, that is, to draw graphics and send it to the display. Since event 1 has been processed, the information of all applications and whether each application has enabled the status bar notification function have been obtained. In other words, all display elements of the target interface have been obtained. Therefore, when the application is set to process the Vsync event, it will draw graphics and send it to the display according to the display elements that have been obtained, so it will be displayed. Figure 2A (c) shows the target interface.
[0059] Therefore, through Figure 2A and Figure 2B It can be seen that when the application switches from the current interface to the target interface, the processing of low-priority events (for example, database access events) takes too long and cannot be interrupted, resulting in high-priority events (for example, Vsync events) being blocked, causing the target interface to fail to appear in time, that is, the interface switching speed is slow, which gives users a stuck application experience.
[0060] Example 2: Application startup scenario
[0061] For example, Figure 3A (a), the electronic device displays the desktop, which includes the browser application icon. After the electronic device receives the operation on the browser application icon, it starts the browser application and displays the following Figure 3A(b) The interface displays a prompt message to prompt the user to wait. Optionally, the prompt message may be present or absent, without limitation. Figure 3A (c) is the home page of the browser application, which includes display elements (e.g., one or more news items) obtained by the browser application from the server. Figure 3A The interface shown in (c) is called the target interface. Figure 3A It can be seen that after receiving an operation to open a target interface, the electronic device needs to wait for a certain period of time before displaying the target interface. From the user's perspective, this feeling of waiting is application lag.
[0062] The following is passed Figure 3B ,illustrate Figure 3A The specific reason why the target interface of the browser application is stuck.
[0063] After receiving the start instruction, the browser application determines that the display elements (for example, various news) in the target interface (i.e., the homepage) need to be obtained from the server, and generates event 1. Event 1 is a server access event used to obtain information from the server. In other words, event 1 is used to obtain the display elements in the target interface. Event 1 is thrown into the event queue of the browser application, such as Figure 3B (a) Because event 1 (i.e., the server access event) has a lower priority, it enters queue 2. The browser application removes event 1 from queue 2 and processes it, obtaining information from the server, specifically, the display elements of the target interface. Optionally, the server may be the application server corresponding to the browser application.
[0064] Before event 1 is processed, the browser application will send an interface update request to the operating system, indicating that the browser application has an interface update requirement. In response to the browser application's interface update request, the operating system throws a Vsync event into the browser application's event queue. Figure 3B (b), since the priority of the Vsync event is higher, the Vsync event enters queue 1. It should be noted that although the Vsync event is a high-priority event, since event 1 (i.e., the server access event) has not been processed yet, it is necessary to wait until event 1 is processed before the Vsync event can be processed. It is understandable that event 1 (i.e., the server access event) is used to obtain information from the server, so it takes a long time, that is, the Vsync event needs to wait for a certain period of time. As mentioned above, the Vsync event is an interface refresh event. If the Vsync event cannot be processed in time, the target interface cannot be updated in time. Therefore, Figure 3A (b) shows the waiting scene.
[0065] like Figure 3B(c) After event 1 is processed, the browser application takes out the Vsync event from queue 1 and processes the Vsync event, that is, it draws graphics and sends them to the display. Since event 1 has been processed, that is, the display elements required for the target interface (for example, various news) have been obtained from the server, when the browser application processes the Vsync event, it draws graphics and sends them to the display according to the display elements that have been obtained, so the display will be displayed. Figure 3A (c) shows the target interface (i.e., the main interface of the browser application).
[0066] Therefore, through Figure 3A and Figure 3B It can be seen that when the application starts, the processing of low-priority events (for example, server access events) takes too long and cannot be interrupted, resulting in high-priority events (for example, Vsync events) being blocked and the main interface of the application cannot be displayed in time, resulting in a slow and stuck application startup experience.
[0067] The above are two examples of application jams. In summary, after the electronic device receives an operation to display the target interface, the processing of low-priority events takes too long and cannot be interrupted, resulting in high-priority events (for example, Vsync events) being blocked and unable to be processed in time, causing the target interface to appear slowly, giving users an application jam experience.
[0068] To prevent application lag, an embodiment of the present application provides an event handling method. In this method, while processing a low-priority event, the application detects whether there is a high-priority event that needs to be processed promptly. If so, the application interrupts the current low-priority event and processes the high-priority event. In this way, high-priority events are prevented from being blocked and unable to be processed promptly, reducing the probability of application lag.
[0069] For example, see Figure 4 The application's event queues include Queue 1 and Queue 2. Queue 1 has a higher priority than Queue 2. Assuming Event 1 enters Queue 2 first, the application processes Event 1 first. While Event 1 is being processed, Event 2 enters Queue 1. The application detects that Event 2 requires prompt processing and interrupts the processing of Event 1 to process Event 2. After Event 2 is processed, the remaining portion of Event 1 is processed. This ensures that Event 2, with its higher priority, is processed promptly.
[0070] The event processing method provided in the embodiment of the present application can be applied to electronic devices. The electronic device can be any device that needs to perform event processing, including but not limited to terminal devices, servers, and interactive devices between terminal devices and servers, such as routers, switches, etc. Taking terminal devices as an example, including but not limited to: mobile phones, tablet computers (portable Android device, PAD), laptop computers, handheld computers and other portable terminal devices; or, watches, bracelets, headphones, helmets and other wearable devices; or, smart TVs, set-top boxes, smart refrigerators, smart sweeping robots and other household appliances; or, car-mounted devices such as car displays and car speakers; or, virtual reality (VR) devices, augmented reality (AR) devices and other devices. In short, the embodiment of the present application does not limit the specific type of terminal devices. Moreover, the operating system of the terminal device can be Android System, Hongmeng system, system, system, system, system, system, Any system, without limitation.
[0071] Next, two application scenarios of the embodiments of the present application are described with examples, wherein application scenario 1 corresponds to Example 1 in the foregoing text, and application scenario 2 corresponds to Example 2 in the foregoing text.
[0072] Application scenario 1: application interface switching scenario
[0073] like Figure 5A (a) The electronic device displays the main interface of the setting application, which includes the option 200 of the notification and status bar. After the electronic device receives the operation for the option 200, it displays the following Figure 5A (b) The interface includes information about some applications in the electronic device (e.g., application icons and / or names) and a switch control corresponding to each application in the application, which is used to turn on or off the status bar notification function of the application. Figure 5A (c) shows more application information and the corresponding switch controls for each application. Figure 5A The interfaces shown in (b) and (c) are called target interfaces. Figure 5A It can be seen that the display elements in the target interface are gradually displayed in batches, not all at once.
[0074] Please compare Figure 5A and the previous article Figure 2A. Figure 2A After the electronic device receives the operation for displaying the target interface, it needs to wait for a certain period of time before displaying the target interface, and all the display elements in the target interface are displayed at once. Figure 5A After the electronic device receives the operation for displaying the target interface, it can display the target interface without waiting, and the display elements in the target interface are gradually displayed in batches. Figure 2A compared to, Figure 5A There is no obvious sense of waiting for users, which improves the user experience.
[0075] The following is passed Figure 5B ,illustrate Figure 5A The implementation principle of .
[0076] After the settings application receives an operation for instructing to open the target interface (for example, the user clicks option 200), it determines that the display elements in the target interface (for example, the information of each application and whether each application has enabled the status bar notification function) need to be obtained through database access, and then generates event 1. Event 1 is a database access event, which is used to obtain the information of each application and whether each application has enabled the status bar notification function from the database. In other words, event 1 is used to obtain the display elements in the target interface. Event 1 is thrown into the event queue of the settings application, such as Figure 5B (a) Since event 1 (i.e., database access event) has a lower priority, event 1 enters queue 2. The application is set to take event 1 from queue 2 and process it. That is, by accessing the database, it obtains information about each application and whether each application has enabled the status bar notification function, that is, obtains the display elements in the target interface.
[0077] Before event 1 is processed, the settings application will send an interface update request to the operating system, indicating that the settings application needs to update the interface. In response to the settings application's interface update request, the operating system throws a Vsync event into the settings application's event queue. Figure 5B (b) Since the Vsync event has a high priority, the Vsync event enters queue 1.
[0078] During the processing of event 1, the application can be set to detect whether there is an event in queue 1 that needs to be processed in time. If it is detected that there is an event in queue 1 that needs to be processed in time, the processing of event 1 will be interrupted and the event that needs to be processed in time will be processed. Figure 5B(c) When the application is set to detect that there is a Vsync event in queue 1 that needs to be processed in time, it will interrupt the processing of event 1 and process the Vsync event. It should be noted that since event 1 (i.e., database access event) has been partially processed, that is, the information of some applications and whether these applications have enabled the status bar notification function have been obtained through database access. In other words, some display elements in the target interface have been obtained. Therefore, when the application is set to process the Vsync event, it can draw and display graphics based on the display elements that have been obtained. Therefore, Figure 5A (b) shows the target interface, in which some display elements are displayed.
[0079] like Figure 5B (d) After the Vsync event is processed, the setting application continues to process the remaining part of event 1 (called event 3), that is, it continues to obtain information about the remaining applications from the database and whether these applications have enabled the status bar notification function, that is, it continues to obtain other display elements in the target interface. It is understandable that since there are still display elements that have not been displayed, the setting application will also send an interface update request to the operating system. The operating system throws another Vsync event into the event queue of the setting application. Since the Vsync event is of high priority, the Vsync event enters queue 1, as shown in the following figure. Figure 5B (e).
[0080] Figure 5B In (e), if the processing time of event 3 is shorter, then after event 3 is processed, the Vsync event is processed. Since event 3 has been processed, the information of the remaining applications and whether these applications have enabled the status bar notification function have been obtained through database access. In other words, the other display elements in the target interface have been obtained. Therefore, when setting the application to process the Vsync event, graphics drawing and display can be performed based on these display elements. Therefore, Figure 5A (c) shows the target interface, which displays all display elements. That is, event 1 (i.e., the database access event) is executed twice (with one interruption), and each of these two times retrieves some of the display elements in the target interface. Through two Vsync events, all display elements in the target interface are displayed.
[0081] Figure 5BIn (e), if the processing of event 3 takes a long time, the processing of event 3 can be interrupted, and then the Vsync event can be processed. It should be noted that since part of event 3 has been processed, part of the display elements have been obtained. Therefore, when processing the Vsync event, graphics drawing and display can be performed based on this part of the display elements. Therefore, there are more display elements in the target interface. It should be understood that since event 3 has not been processed, not all display elements have been displayed in the target interface. After processing the Vsync event, the remaining part of event 3 (called event 4) is processed. The processing principle of event 4 is the same as that of event 3 and will not be repeated. In other words, event 1 (i.e., database access event) is executed multiple times (interrupted multiple times), and each time part of the display elements in the target interface are obtained, and through multiple Vsync events, the display elements in the target interface are refreshed in multiple batches.
[0082] Application scenario 2: application startup scenario
[0083] like Figure 6A (a), the electronic device displays the desktop, which includes the browser application icon. After the electronic device receives the operation on the browser application icon, it starts the browser application and displays the following Figure 6A (b) is the home page of the browser application, which includes one or more news items. Figure 6A (c) interface, which displays more news. Figure 6A The interface between (b) and (c) is called the target interface. Figure 6A It can be seen that the display elements in the target interface (for example, multiple news items) are gradually displayed in batches, rather than all displayed at once.
[0084] Please compare Figure 6A Compared with the previous article Figure 3A . Figure 3A After receiving the start instruction, the browser application needs to wait for a certain period of time before the target interface is displayed, and all the display elements (ie, multiple news items) in the target interface are displayed at one time. Figure 6A After the browser application receives the start command, the target interface will appear without waiting, and the display elements in the target interface will be displayed gradually in batches. Figure 3A compared to, Figure 6A There is no obvious sense of waiting for users, which improves the user experience.
[0085] The following is passed Figure 6B ,illustrate Figure 6A The implementation principle of .
[0086] After receiving the start instruction, the browser application determines that the display elements (for example, news items) in the target interface need to be obtained from the server, and generates event 1. Event 1 is a server access event used to obtain information from the server. In other words, event 1 is used to obtain the display elements in the target interface. Event 1 is thrown into the event queue of the browser application. Figure 6B (a) Because event 1 (i.e., the server access event) has a lower priority, event 1 enters queue 2. The browser application removes event 1 from queue 2 and processes it, i.e., obtains the display element within the target interface. Optionally, the server may be an application server corresponding to the browser application.
[0087] Before event 1 is processed, the browser application sends an interface update request to the operating system, indicating that the browser application has an interface update requirement. In response to the browser application's interface update request, the operating system throws a Vsync event into the browser application's event queue. Figure 6B (b) Since the Vsync event has a high priority, the Vsync event enters queue 1.
[0088] During the processing of event 1, the browser application can detect whether there is an event in queue 1 that needs to be processed in time. If it is detected that there is an event in queue 1 that needs to be processed in time, the processing of event 1 will be interrupted and the event that needs to be processed in time will be processed. Figure 6B (c) When the browser application detects that there is a Vsync event in queue 1 that needs to be processed in time, it interrupts the processing of event 1 and processes the Vsync event. It should be noted that since event 1 (i.e., server access event) has been partially processed, that is, some information (e.g., one or more news items) has been obtained from the server, in other words, some display elements in the target interface have been obtained. Therefore, when the browser application processes the Vsync event, it can draw and display graphics based on these display elements. Therefore, Figure 6A (b) shows the target interface, which includes some display elements, such as one or more news items.
[0089] like Figure 6B (d) After the Vsync event is processed, the browser application continues to process the remaining part of event 1 (called event 3), that is, it continues to obtain other display elements in the target interface. It is understandable that since there are still display elements that have not been displayed, the browser application will also send an interface update request to the operating system. The operating system throws another Vsync event into the browser application's event queue. Since the Vsync event has a high priority, the Vsync event enters queue 1, as shown in the following figure. Figure 6B (e).
[0090] Figure 6BIn (e), if the processing time of event 3 is shorter, then after event 3 is processed, the Vsync event is processed. Since event 3 has been processed, the other display elements in the target interface have been obtained. Therefore, when processing the Vsync event, graphics can be drawn and displayed based on these display elements. Figure 6B (b) shows the target interface, which displays all display elements. That is, event 1 (i.e., the server access event) is executed twice (with one interruption), and each of these two times retrieves some of the display elements in the target interface. Through two Vsync events, the display elements in the target interface are refreshed twice.
[0091] Figure 6B In (e), if the processing of event 3 takes a long time, then the processing of event 3 can be interrupted, and then the Vsync event can be processed. Similarly, since part of event 3 has been processed, part of the display elements have been obtained. Therefore, when processing the Vsync event, graphics drawing and display can be performed based on this part of the display elements. Therefore, there are a part of the display elements in the target interface. It should be understood that since event 3 has not been processed, not all display elements have been displayed in the target interface. After processing the Vsync event, the remaining part of event 3 (called event 4) continues to be processed. The processing principle of event 4 is the same as that of event 3 and will not be repeated. In other words, event 1 (i.e., the server access event) is executed multiple times (interrupted multiple times), and each time part of the display elements in the target interface are obtained, and the display elements in the target interface are refreshed multiple times through multiple Vsync events.
[0092] The above is an example of the application scenario of the embodiment of the present application. It should be understood that the above application scenario is only an example and does not constitute a limitation of the present application. In addition to the above application scenario, the technical solution of the embodiment of the present application can also be applied to other application scenarios.
[0093] Based on the above application scenarios, the technical solutions of the embodiments of the present application are described in detail below.
[0094] For ease of understanding, the following description uses the first application in an electronic device as an example. The first application can be the settings application described in Application Scenario 1 above, or the browser application described in Application Scenario 2. In short, the embodiment of the present application does not limit the type of the first application. Furthermore, the first application can be a system application or a third-party application, without limitation.
[0095] In an embodiment of the present application, after receiving a startup instruction from a first application, the electronic device starts the first application and creates an event queue for the first application to store pending events of the first application. The electronic device's operating system may be responsible for creating the event queue for the first application. Optionally, the operating system may create an event queue for the first application in an active or passive manner. Taking the active creation of an event queue for the first application as an example, for example, the electronic device's desktop displays an application icon for the first application. After the electronic device's operating system receives an operation on the application icon for the first application, it sends a startup instruction to the first application, and the operating system actively creates an event queue for the first application. Taking the passive creation of an event queue for the first application as an example, for example, after receiving the startup instruction, the first application sends a request to the operating system to request the creation of an event queue for the first application. The operating system creates an event queue for the first application in response to the request sent by the application. The operating system creating an event queue for the first application may include: creating an event queue for the first application in the memory resources allocated for the first application, and sending information about the event queue (e.g., a storage address) to the first application. The first application retrieves the pending events from the event queue using the storage address and processes the pending events. The operating system sending the storage address of the event queue to the first application may include: the operating system sending the storage address of the event queue to the first application via a first interface. Optionally, the first interface may be an interface provided by the operating system of the electronic device. Exemplarily, the first interface may be an application programming interface (API). It is understood that after the first application exits, the operating system may cancel the event queue created for the first application to release occupied memory resources.
[0096] Optionally, the number of event queues for the first application may be one or more. In some embodiments, the number of event queues is preconfigured for the first application. For example, the number of event queues is pre-set in the application package of the first application. The operating system of the electronic device determines the number of event queues for the first application based on the application package of the first application, and then creates the same number of event queues for the first application. In other embodiments, the number of event queues is pre-configured by the operating system of the electronic device. Therefore, when the operating system creates event queues for the first application, the same number of event queues is created for the first application based on the number of event queues pre-set by the operating system. Optionally, for different applications, the number of event queues pre-configured by the operating system may be the same or different, without limitation.
[0097] When the first application has multiple event queues, different event queues can correspond to different priorities. For example, the event queue of the first application includes two queues. For example, see Figure 7The first application's event queues include Queue 1 and Queue 2, with Queue 1 having a higher priority than Queue 2. That is, Queue 1 stores higher-priority events, while Queue 2 stores lower-priority events. The first application's pending events are placed in the corresponding queues according to their priority. For example, if pending event 1 has a lower priority, it will be placed in Queue 2; if pending event 2 has a higher priority, it will be placed in Queue 1.
[0098] After the event queue of the first application is successfully created, the event thrower (also called event producer) can throw pending events into the event queue of the first application. Optionally, the event thrower of the first application can be the main thread of the first application, the child thread of the first application, the main thread of other applications, the child thread of other applications, the operating system, etc., without limitation. Figure 5B For example, the thrower of event 1 (i.e. database access event) is the main thread of the application, and the thrower of the Vsync event is the operating system. Figure 6B For example, the thrower of event 1 (ie, server access event) is the main thread of the browser application, and the thrower of the Vsync event is the operating system.
[0099] Continue with Figure 7 Taking the two queues shown as an example, after an event thrower generates a pending event, it can determine the priority of the pending event and then, based on the priority of the pending event, throw the pending event into the event queue of the corresponding level. One possible way to determine the priority of the pending event is to determine the priority of the pending event by querying a corresponding relationship, where the corresponding relationship is used to describe the priority of various pending events of the first application. Optionally, the first corresponding relationship can be preconfigured.
[0100] Continue with Figure 7 For example, see the two queues shown in Figure 8 , is a flow chart of an event processing method provided by an embodiment of the present application. This method can be applied to Figure 7 The scene shown. Figure 8 , the process includes the following steps:
[0101] Step 801 , event 1 enters queue 2 .
[0102] Taking the first application as the settings application as an example, event 1 can be the Figure 5B The event 1 in the above example is the database access event. Taking the first application as a browser application, the event 1 can be the event in the previous application scenario 2. Figure 6B Event 1 in the event is the server access event.
[0103] Step 802: The first application processes event 1.
[0104] Event 1 is the first application scenario in the previous article. Figure 5B For example, the first application processes event 1, which is to obtain information from the database, such as the information of each application and whether each application has enabled the status bar notification function. Figure 6B Taking the server access event in as an example, the first application processes event 1, that is, obtaining information from the server, such as news.
[0105] As mentioned above, after the operating system of the electronic device creates event queues (e.g., Queue 1 and Queue 2) for the first application, it sends the storage addresses of the event queues to the first application via the first interface. In this way, the first application can retrieve pending events from the event queues using the storage addresses and process them. For example, the first application retrieves event 1 from Queue 2 based on the storage address of Queue 2 and processes event 1.
[0106] Step 803: Event 2 enters queue 1.
[0107] For example, event 2 may be a Vsync event. It should be noted that the execution order of step 803 and subsequent steps 804 and 805 is not limited. For example, step 803 may occur after step 804, or after step 805.
[0108] Step 804 : The first application determines whether the currently processed event is of the highest priority. If so, the currently processed event cannot be interrupted. Otherwise, step 805 is executed.
[0109] For example, if the first application determines that the currently processed event comes from queue 1, that is, from the queue with the highest priority, then the priority of the currently processed event is determined to be the highest, and the currently processed event is not interrupted. If the first application determines that the currently processed event comes from queue 2, that is, from the low-priority queue, then the priority of the currently processed event is determined not to be the highest, and the currently processed event can be interrupted. In other words, events in the high-priority queue cannot be interrupted, but events in the low-priority queue can be interrupted. Optionally, step 804 can be executed or not, without limitation, so Figure 8 Step 804 is indicated by a dotted line.
[0110] Step 805 , during the processing of event 1 , the first application detects whether there is an event in queue 1 that needs to be processed in a timely manner. If so, step 806 is executed; otherwise, step 805 may be executed again.
[0111] Optionally, before step 805, the first application may further determine whether event 1 satisfies a first condition. If so, step 805 is executed; otherwise, step 805 is not executed. Optionally, the first condition includes at least one of the following:
[0112] (1) The total processing time of event 1 exceeds the duration threshold 1. The specific value of the duration threshold 1 is not limited. That is to say, if event 1 is a long-time event, the first application detects whether there is an event 2 in queue 1 that needs to be processed in a timely manner during the processing of event 1. In this way, the first application needs to determine the total processing time of event 1. One possible way is that the total processing time of event 1 is preset. For example, the total processing time of event 1 is preset in the application package of the first application. The first application can determine the total processing time of event 1 based on the application package, and then determine whether event 1 is a long-time event. Another possible way is that the first application evaluates the total processing time of event 1 based on the event type of event 1. For example, if the event type of event 1 is a database access event or a server access event, it is determined that event 1 is a long-time event.
[0113] (2) The processing duration of event 1 reaches duration threshold 2. For example, when the first application starts processing event 1, the timer starts timing. When the timer reaches duration threshold 2, it is determined that the processing duration of event 1 reaches duration threshold 2. The specific value of duration threshold 2 is not limited in the embodiment of the present application. In other words, if the processing duration of event 1 exceeds duration threshold 2, the first application detects whether there is event 2 in queue 1 that needs to be processed in a timely manner.
[0114] If the first application determines that event 1 meets the first condition, step 805 is executed to detect whether there is event 2 that needs to be processed in a timely manner in queue 1. Event 2 that needs to be processed in a timely manner meets the second condition. Optionally, the second condition includes at least one of the following:
[0115] (1) Event 2 is an event that needs to provide feedback to the user. For example, an interface refresh event (e.g., a Vsync event). Optionally, an event that needs to provide feedback to the user can be generated spontaneously by the electronic device, or can be generated by user triggering. Taking user triggering as an example, for example, in the aforementioned application scenario one, the setting application generates a Vsync event when triggered by the user; or, in the aforementioned application scenario two, the browser application generates a Vsync event when triggered by the user. Taking the spontaneous generation of an electronic device as an example, for example, the first application displays a GIF, and the GIF includes multiple frames of images. Before displaying the next frame of the image, the first application automatically sends an interface update request to the operating system. In response to the interface update request, the operating system throws a Vsync event into the event queue of the first application. The first application processes the Vsync event to display the next frame of the image. Optionally, in addition to the Vsync event, the event that needs to provide feedback to the user can also be other events, such as sound playback events, vibration feedback events, etc., which are not listed one by one.
[0116] (2) The waiting time of event 2 in queue 1 exceeds time threshold 3. That is, if event 2 in queue 1 has been waiting for a long time, the first application interrupts the currently processed event 1 and processes event 2. Exemplarily, time threshold 3 can be 4ms, 40ms, 400ms, etc., and the specific value is not limited.
[0117] (3) The total processing time of event 2 is less than the duration threshold 4. The specific value of the duration threshold 4 is not limited. Optionally, the duration threshold 4 is less than or equal to the duration threshold 1 mentioned above. In other words, if event 2 in queue 1 is a short-time event, the first application can interrupt the currently processed event 1 and process event 2. In this way, the first application needs to determine the total processing time of event 2, which is the same as the principle of determining the total processing time of event 1 in the previous article and will not be repeated.
[0118] Optionally, the first application detecting whether there is an event 2 in queue 1 that requires timely processing may include: the first application detecting whether there is an event 2 in queue 1 that requires timely processing based on the storage address of queue 1. The storage address of queue 1 may be sent to the first application by the operating system of the electronic device via the first interface. This part has been described above and will not be repeated here.
[0119] Step 807: The first application processes event 2.
[0120] Taking event 2 being a Vsync event as an example, the first application processes the Vsync event, that is, the first application executes a graphics drawing and display sending process to refresh the interface.
[0121] In some embodiments, the first application processes event 2, which may include: the first application processes event 2 according to the processed part of event 1. Taking the first application as a setting application as an example, event 1 may be the database access event in the aforementioned application scenario one, that is, event 1 is used to obtain the display elements in the target interface of the setting application. The processed part of event 1 includes: the acquired display elements. It is understandable that since event 1 has not been processed, the acquired display elements are partial display elements in the target interface. Therefore, the first application processes event 2 according to the processed part of event 1, that is, according to the acquired display elements, it processes event 2 to display the target interface, and the target interface includes the acquired display elements, that is, partial display elements are displayed in the target interface.
[0122] Optionally, if the event queue of the first application also includes queue 3, and the priority of queue 3 is higher than that of queue 1, then during the processing of event 2, the first application can also detect whether there are events in queue 3 that need to be processed in a timely manner; if it is detected that there are events in queue 3 that need to be processed in a timely manner, the processing of event 2 is interrupted and the events in queue 3 are processed. The principle is the same and will not be repeated.
[0123] Step 808 : The first application processes the remaining portion of event 1 .
[0124] Optionally, before step 808, the process may further include: the first application generates event 3 based on the remaining portion of event 1, and event 3 enters the event queue of the first application to wait for processing. Event 3 may include the unprocessed portion of event 1, and optionally, may also include context information between the processed and unprocessed portions of event 1. The context information may include the application identifier of the first application, the event identifier of event 1, the processing progress of event 1, and the like. As described above, event 3 enters the event queue of the first application, and the event queue of the first application includes queue 1 and queue 2. Optionally, event 3 may enter queue 1 or queue 2. Taking event 3 entering queue 1 as an example, that is, event 1 originally entered queue 2, and after event 1 was interrupted, the remaining portion of event 1 generated event 3, and the priority of event 3 was increased, and the event entered queue 1. Taking event 3 entering queue 2 as an example, that is, event 1 originally entered queue 2, and after event 1 was interrupted, the remaining portion of event 1 generated event 3, and the priority of event 3 remained unchanged, and the event entered queue 2. Optionally, when event 3 enters the event queue of the first application, it can enter the tail or the head of the event queue. Taking event 3 entering queue 2 as an example, in order to ensure that event 3 can be processed as quickly as possible, event 3 can be placed at the head of queue 2.
[0125] After event 3 enters the event queue of the first application, the first application can take event 3 out of the event queue and process event 3. Optionally, during the processing of event 3, the first application can detect whether there are events in queue 1 that need to be processed in a timely manner. If so, the processing of event 3 can be interrupted to process the events that need to be processed in a timely manner. Optionally, before detecting whether there are events in queue 1 that need to be processed in a timely manner, the first application can determine whether event 3 meets the first condition, such as whether the total processing time of event 3 exceeds the duration threshold 5, and / or whether the processed duration of event 3 exceeds the duration threshold 6. If event 3 meets the first condition, it detects whether there are events in queue 1 that need to be processed in a timely manner. The detailed description of the first condition has been described above and will not be repeated. Optionally, the events that need to be processed in a timely manner in queue 1 meet the second condition, such as events that need to provide feedback to the user, events whose waiting time in queue 1 exceeds the preset threshold 7, etc. The detailed description of the second condition has been described above and will not be repeated.
[0126] Continuing with the example of the first application being the settings application, Event 1 could be the database access event described in Scenario 1 above. That is, Event 1 is used to retrieve display elements within the settings application's target interface. The processed portion of Event 1 includes the retrieved display elements. Therefore, the unprocessed portion of Event 1, Event 3, is used to retrieve other display elements within the target interface. During the processing of Event 3, the first application detects an event in Queue 1 that requires prompt processing, such as a Vsync event.
[0127] If the processing time of event 3 is shorter, then after the first application processes event 3, it processes the Vsync event in queue 1 according to the processing result of event 3. As mentioned above, event 3 is used to obtain other display elements in the target interface. Therefore, the processing result of event 3 includes the other display elements that have been obtained. Therefore, the first application processes the Vsync event according to the processing result of event 3, that is, it displays the target interface according to the other display elements that have been obtained, and the target interface includes the other display elements. Since event 1 has been processed, all display elements have been displayed in the target interface. Therefore, in this scenario, event 1 is interrupted once, that is, event 1 is processed twice, and part of the display elements of the target interface are obtained each time, and all display elements in the target interface are displayed through two Vsync events.
[0128] If the processing of event 3 takes a long time, the first application interrupts the processing of event 3 and processes the Vsync event. For example, the first application can process the Vsync event based on the processed part of event 3. The processed part of event 3 includes: some display elements that have been obtained. Therefore, the first application processes the Vsync event based on the processed part of event 3, that is, displays the target interface based on the obtained part of display elements, and the target interface includes the obtained part of display elements. It should be noted that since event 3 has not been processed, not all display elements in the target interface have been displayed. Since event 3 is interrupted, the first application can generate event 4 based on the remaining part of event 3, and then process event 4. The processing process of event 4 is the same as that of event 3, and will not be repeated. Therefore, in this scenario, event 1 is interrupted multiple times, that is, event 1 is processed three or more times, and each time part of the display elements of the target interface are obtained, and all display elements in the target interface are displayed through three or more Vsync events.
[0129] As mentioned above, during the processing of event 1, the first application detects whether event 2 requiring prompt processing exists in queue 1. As a possible implementation, event 1 includes multiple sub-events. The first application may perform a detection step once between the processing intervals of every two adjacent sub-events. This detection step is used to detect whether event 2 requiring prompt processing exists in queue 1. The processing interval between two adjacent sub-events may include the time period from the end of processing of the previous sub-event to the start of processing of the next sub-event.
[0130] For example, see Figure 9 In (a), queue 2 includes event 1, and event 1 includes sub-events 1a, 1b, 1c, and 1d. The first application takes event 1 out of queue 2 and processes each sub-event of event 1 in sequence. After each sub-event is processed, a detection step is performed. If no event that needs to be processed in time is detected in queue 1, the next sub-event of event 1 is processed. If event 2 that needs to be processed in time is detected in queue 1, the processing of event 1 is interrupted and event 2 is processed. For example, Figure 9 In (b), after the first application processes sub-event 1b (the processed sub-event is indicated in black), it detects that queue 1 includes event 2 that needs to be processed in a timely manner. Figure 9 In (c), the first application generates event 3 based on the unprocessed part of event 1, and event 3 enters queue 2 to wait for processing. The first application then takes event 2 out of queue 1 and processes it. Figure 9In (d) of the figure, after event 2 is processed (indicated by black), the first application removes event 3 from queue 2 and processes it. Event 3 consists of multiple sub-events. During the interval between processing two adjacent sub-events, it can detect whether there are any events in queue 1 that need to be processed promptly. The principle is the same and will not be repeated here.
[0131] Optionally, the first application performs a detection step, which may include: the first application calls a query interface, and detects whether there is an event 2 in queue 1 that needs to be processed in a timely manner through the query interface. The query interface may be configured by the operating system. For example, the query interface may be an application programming interface (API). One possible scenario is that after the operating system creates an event queue for the first application, it opens the query interface to the first application, so that the first application can query whether there is an event in the queue that needs to be processed in a timely manner through the query interface. Optionally, the query interfaces corresponding to different applications may be the same or different. Taking different as an example, for example, the first application corresponds to query interface 1, and the second application corresponds to query interface 2, so that information leakage of the application can be avoided.
[0132] As mentioned above, event 1 may include multiple sub-events. As a possible implementation method, event 1 is split into multiple sub-events. Optionally, the splitting process of event 1 may occur before event 1 is enqueued, or after event 1 is enqueued. Taking the case before event 1 is enqueued as an example, after the event thrower generates event 1, event 1 is split into multiple sub-events, and then event 1 split into multiple sub-events is thrown into the event queue of the first application. Taking the case after event 1 is enqueued as an example, for example, after the first application takes event 1 out of the event queue, it splits event 1 into multiple sub-events, and then performs a detection step within the processing interval between each two adjacent sub-events in the multiple sub-events.
[0133] Optionally, the event splitting method may include splitting by function or splitting by duration.
[0134] Taking the functional split as an example, each sub-event in the multiple sub-events obtained by splitting is used to implement different functions. Taking event 1 in the previous application scenario one, that is, the database access event, as an example, event 1 is used to obtain information about various applications in the electronic device from the database. Therefore, event 1 can be split into multiple sub-events, each sub-event is used to obtain information about one or more applications, for example, each sub-event is used to obtain information about 3 applications. Taking event 1 in the previous application scenario two, that is, the server access event, as an example, event 1 is used to obtain information from the server, such as news. Therefore, event 1 can be split into multiple sub-events, each sub-event is used to obtain one or more news, for example, each sub-event is used to obtain 3 news.
[0135] Taking the splitting by duration as an example, for example, the processing time of each of the multiple sub-events obtained by splitting is the same, which is T / N, where T is the total processing time of event 1.
[0136] In the above embodiment, the event queue of the first application includes two queues. It is understandable that the event queue of the first application may include more queues, such as 3 queues, 5 queues, etc. As an example, see Figure 10 The event queue of the first application includes five queues, from queue 1 to queue 5. These five queues correspond to different priorities, and the priorities gradually decrease from queue 1 to queue 5. The following Table 1 exemplifies the priorities of the five queues and the types of pending events stored in each queue.
[0137] Table 1: Priority and event type of the event queue of the first application
[0138]
[0139] It should be noted that the event types in Table 1 above are merely examples and do not constitute a limitation on the embodiments of the present application.
[0140] based on Figure 10 The event queue of the first application is shown in Figure 11 , is another flow chart of an event processing method provided in an embodiment of the present application, which can be applied to Figure 10 The scene shown. Figure 11 , the process of the method includes:
[0141] Step 1100: Determine the priority of the currently processed event, which is represented by Prio.
[0142] Step 1101 , determining whether the priority of the currently processed event is VIP level, if so, the currently processed event cannot be interrupted, otherwise, executing step 1102 .
[0143] Step 1102 , determine whether the priority of the currently processed event is immediate. If so, execute step 1103 ; otherwise, execute step 1104 .
[0144] Step 1103 , determine whether there is an event in the VIP queue that exceeds 4ms. If so, the current event processing can be interrupted; otherwise, the current event processing cannot be interrupted.
[0145] Therefore, it can be seen from steps 1102 to 1103 that if the currently processed event is of the immediate level, which means it is not the highest priority, then the first application needs to detect whether there are events in the queue with a higher priority (i.e., the VIP queue) that need to be processed in a timely manner (for example, events with a waiting time of more than 4ms). If so, the currently processed event is interrupted and the events in the higher priority queue (i.e., the VIP queue) that need to be processed in a timely manner are processed. If not, the currently processed event is not interrupted.
[0146] Step 1104 , determine whether the priority of the currently processed event is high level, if yes, execute step 1105 , otherwise, execute step 1107 .
[0147] Step 1105 , determine whether there is an event in the VIP queue that exceeds 4ms. If so, the current event processing can be interrupted. Otherwise, execute step 1106 .
[0148] Step 1106 , determine whether there is an event in the immediate queue that takes longer than 40ms. If so, the current event processing can be interrupted; otherwise, the current event processing cannot be interrupted.
[0149] Therefore, it can be seen from steps 1104 to 1106 that if the currently processed event is at a high level, which means it is not the highest priority, then the first application needs to detect whether there are events that need to be processed in a timely manner in a higher priority queue (i.e., the VIP queue and the immediate level). If so, the currently processed event is interrupted, and the events that need to be processed in a timely manner in the higher priority queue (i.e., the VIP queue and the immediate level) are processed. If not, the currently processed event is not interrupted.
[0150] It should be noted that when the current processing event is at a high level, there are two queues with higher priorities than the high level, namely the VIP-level queue and the immediate-level queue. The first application can first determine whether there are events in the VIP-level queue that need to be processed in a timely manner (for example, events with a waiting time of more than 4ms). If so, the current processing event will be interrupted, and the events in the VIP queue that need to be processed in a timely manner will be processed. If not, the current processing event will be determined whether there are events in the immediate-level queue that need to be processed in a timely manner (for example, events with a waiting time of more than 40ms). If so, the current processing event will be interrupted, and the events in the immediate-level queue that need to be processed in a timely manner will be processed. If not, the current processing event cannot be interrupted.
[0151] As previously described, if the first application detects an event requiring immediate processing (called event a) in the VIP queue, it will interrupt the current event processing and process event a in the VIP queue. Optionally, after processing event a, the first application can check whether there are any events requiring immediate processing in the immediate-level queue. If not, the first application will continue processing the unprocessed portion of the interrupted event. If so, the first application will process the event requiring immediate processing in the immediate-level queue. After processing that event, the first application will continue processing the unprocessed portion of the interrupted event.
[0152] Step 1107 , determine whether the priority of the currently processed event is low level, if yes, execute step 1108 , otherwise, execute step 1111 .
[0153] Step 1108 , determine whether there is an event in the VIP queue that exceeds 4ms. If so, the current event processing can be interrupted. Otherwise, execute step 1109 .
[0154] Step 1109 , determine whether there is an event in the immediate queue that takes longer than 40ms. If so, the current event processing can be interrupted. Otherwise, execute step 1110 .
[0155] Step 1110 , determine whether there is an event in the high queue that exceeds 400ms. If so, the current event processing can be interrupted; otherwise, the current event processing cannot be interrupted.
[0156] Therefore, it can be seen from steps 1107 to 1110 that if the currently processed event is of low level, which means it is not the highest priority, then the first application needs to detect whether there are events that need to be processed in a timely manner in queues with higher priority (i.e. VIP queues, immediate level, high level queues). If so, the currently processed event is interrupted, and events that need to be processed in a timely manner in queues with higher priority (i.e. VIP queues, immediate level, high level queues) are processed. If not, the currently processed event is not interrupted.
[0157] Step 1111, determine whether the priority of the current processing event is Idle level, if yes, execute step 1112, otherwise, the current processing event cannot be interrupted.
[0158] It should be noted that if the currently processed event is not an event of any of the five levels, the currently processed event cannot be interrupted to avoid anomalies in the first application.
[0159] Step 1112: determine whether there are events in other queues. If so, the current event processing can be interrupted. Otherwise, the current event processing cannot be interrupted.
[0160] Therefore, if the currently processed event is an Idle-level event, then once an event is detected in another queue, the current event processing is interrupted and the event in the other queue is processed. Optionally, when the currently processed event is an Idle-level event, the first application can check whether there are events in the first four queues in descending order of priority. Once an event is detected in any queue, the current event processing is interrupted and the detected event is processed.
[0161] See Figure 12 , is a structural diagram of an electronic device provided in an embodiment of the present application. The electronic device may be the electronic device mentioned above, such as a mobile phone. Figure 12 As shown, the electronic device 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.
[0162] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors. The controller may serve as the nerve center and command center of the electronic device. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution. The processor 110 may also include memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a high-speed cache memory. This memory may store instructions or data that have just been used or are being recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces the processor 110's waiting time, and thus improves system efficiency.
[0163] In some embodiments, the processor 110 may execute the event processing method provided in the embodiments of the present application. For example, while processing a low-priority event, the processor 110 may detect whether there is a high-priority event that needs to be processed promptly. If so, the processor 110 may interrupt the currently processed low-priority event and process the high-priority event, thereby preventing the high-priority event from being blocked and unable to be processed promptly, and reducing the probability of application lag.
[0164] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0165] The I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple I2C bus lines. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, and the like via different I2C bus interfaces. For example, the processor 110 may be coupled to the touch sensor 180K via the I2C interface, enabling communication between the processor 110 and the touch sensor 180K via the I2C bus interface, thereby implementing the touch function of the electronic device 100.
[0166] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface, enabling the function of answering calls through a Bluetooth headset.
[0167] The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0168] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality. In some embodiments, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface, enabling the function of playing music through Bluetooth headphones.
[0169] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display 194 and the camera 193. MIPI interfaces include the camera serial interface (CSI) and the display serial interface (DSI). In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the camera function of the electronic device 100. The processor 110 and the display 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0170] The GPIO interface can be configured via software. The GPIO interface can be configured as either a control signal or a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 to the camera 193, display 194, wireless communication module 160, audio module 170, sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0171] The USB interface 130 is an interface that complies with USB standards and may be a Mini USB interface, a Micro USB interface, a USB Type-C interface, or the like. The USB interface 130 can be used to connect a charger to charge the electronic device 100, or to transfer data between the electronic device 100 and peripheral devices. It can also be used to connect headphones to play audio. This interface can also be used to connect other electronic devices, such as augmented reality devices.
[0172] It is understood that the interface connection relationship between the modules illustrated in the embodiment of the present invention is merely an illustrative illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0173] The wireless communication function of the electronic device can be implemented using antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, a modem processor, and a baseband processor. Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antenna can be used in conjunction with a tuning switch.
[0174] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied in electronic devices. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0175] The wireless communication module 160 can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. The wireless communication module 160 can be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0176] In some embodiments, antenna 1 of the electronic device is coupled to mobile communication module 150 , and antenna 2 is coupled to wireless communication module 160 , so that the electronic device can communicate with the network and other devices through wireless communication technology.
[0177] The display screen 194 is used to display the display interface of the application, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0178] The electronic device 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor, etc. Among them, the ISP is used to process the data fed back by the camera 193.
[0179] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 121. For example, the processor 110 executes the event processing method provided in the embodiment of the present application by running the instructions stored in the internal memory 121. Among them, the program storage area can store an operating system, and the software code of at least one application, etc. The data storage area can store data (such as images, videos, etc.) generated during the use of the electronic device, etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash memory, etc.
[0180] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as pictures and videos can be stored on the external memory card.
[0181] The electronic device can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0182] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.
[0183] The speaker 170A, also called a "speaker," is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or listen to external speaker scenarios such as hands-free calls through one or more speakers 170A.
[0184] The receiver 170B, also called "earpiece", can be one or more and is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be heard by placing the receiver 170B close to the human ear.
[0185] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals.
[0186] The headphone jack 170D is used to connect a wired headphone.
[0187] The pressure sensor 180A is used to sense the pressure signal and convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be disposed on the display screen 194 .
[0188] The gyro sensor 180B can be used to determine the motion posture of the electronic device. In some embodiments, the gyro sensor 180B can be used to determine the angular velocity of the electronic device around three axes (i.e., the x, y, and z axes). The gyro sensor 180B can also be used for anti-shake photography.
[0189] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device calculates the altitude using the air pressure value measured by the air pressure sensor 180C to assist in positioning and navigation.
[0190] The magnetic sensor 180D includes a Hall sensor, and the electronic device can use the magnetic sensor 180D to detect the opening and closing of the flip cover.
[0191] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device in various directions (generally three axes) and the magnitude and direction of gravity when the electronic device is stationary.
[0192] The distance sensor 180F is used to measure distance. The electronic device can measure distance using infrared or laser.
[0193] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device emits infrared light through the light emitting diode. The electronic device uses the photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device. When insufficient reflected light is detected, the electronic device can determine that there is no object near the electronic device.
[0194] The ambient light sensor 180L is used to sense the brightness of the ambient light. The electronic device can adaptively adjust the brightness of the display screen 194 according to the sensed ambient light brightness.
[0195] The fingerprint sensor 180H is used to collect fingerprints.
[0196] The temperature sensor 180J is used to detect temperature.
[0197] The touch sensor 180K, also known as a "touch panel," can be mounted on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also known as a "touch screen." The touch sensor 180K is used to detect touch operations applied to or near it. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event.
[0198] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone in a human vocal part.
[0199] The buttons 190 include a power button, a volume button, etc. The button 190 can be a mechanical button. It can also be a touch button. The electronic device can receive button input and generate key signal input related to the user settings and function control of the electronic device. The motor 191 can generate a vibration prompt. The motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. The indicator 192 can be an indicator light, which can be used to indicate the charging status, power changes, messages, missed calls, notifications, etc. The SIM card interface 195 is used to connect the SIM card. The SIM card can be connected to and separated from the electronic device by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195.
[0200] It is understandable that Figure 12 The components shown do not constitute a specific limitation on the electronic device. The electronic device in the embodiment of the present invention may include Figure 12 More or fewer components in . In addition, Figure 12 The combination / connection relationship between the components can also be adjusted and modified.
[0201] Figure 13 The electronic device 1300 is a schematic diagram of the structure of the electronic device 1300 provided in the embodiment of the present application. The electronic device 1300 can be the electronic device mentioned above, such as a mobile phone. Figure 13As shown, the electronic device 1300 may include: one or more processors 1301; one or more memories 1302; a communication interface 1303, and one or more computer programs 1304. The above-mentioned components may be connected via one or more communication buses 1305. The one or more computer programs 1304 are stored in the above-mentioned memory 1302 and are configured to be executed by the one or more processors 1301. The one or more computer programs 1304 include instructions. For example, when the electronic device 1300 is the electronic device described above, the instructions may be used to execute the relevant steps of the electronic device in the corresponding embodiment above. The communication interface 1303 is used to enable communication between the electronic device 1300 and other devices. For example, the communication interface may be a transceiver.
[0202] Based on the above, this application further provides a computer-readable storage medium storing instructions that, when executed, implement the method provided in any of the above method embodiments. The computer-readable storage medium may include any medium capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory, a random access memory, a magnetic disk, or an optical disk.
[0203] Based on the above, the present application further provides a computer program product, which includes: a computer program (also referred to as code or instructions), which, when executed on a computer, causes the computer to perform the method provided in any of the above method embodiments. Optionally, the computer may be a terminal device, such as a mobile phone.
[0204] In the embodiments provided in the present application above, the method provided in the embodiment of the present application is introduced from the perspective of an electronic device (e.g., a mobile phone) as an execution subject. In order to implement the various functions in the method provided in the embodiment of the present application above, the electronic device may include a hardware structure and / or a software module to implement the above functions in the form of a hardware structure, a software module, or a hardware structure plus a software module. Whether a function of the above functions is executed in the form of a hardware structure, a software module, or a hardware structure plus a software module depends on the specific application and design constraints of the technical solution.
[0205] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)). In the absence of conflict, the solutions of the above embodiments can be used in combination.
[0206] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0207] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0208] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0209] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0210] Obviously, those skilled in the art may make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include these modifications and variations.
Claims
1. An event processing method, characterized in that: Applied to an electronic device, the electronic device includes a first application, the event queue of the first application includes a first queue and a second queue, the first queue and the second queue are respectively used to store pending events of the first application, and the priority of the first queue is higher than the priority of the second queue, the method comprising: Processing a first event in the second queue; During the processing of the first event, detecting whether there is a second event in the first queue that needs to be processed in a timely manner; If it is detected that a second event that needs to be processed in a timely manner exists in the first queue, the processing of the first event is interrupted and the second event is processed.
2. The method according to claim 1, characterized in that The second event is an event that requires feedback information to the user, and / or the waiting time of the second event in the first queue exceeds the first time.
3. The method according to claim 1 or 2, characterized in that Before detecting whether there is a second event that needs to be processed in a timely manner in the first queue, the method further includes: It is determined that the total processing time of the first event exceeds a second duration, and / or that the processing time of the first event exceeds a third duration.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: A third event is generated according to an unprocessed portion of the first event, and the third event enters the first queue or the second queue to wait for processing.
5. The method according to claim 4, characterized in that When the third event enters the second queue, the third event is located at the head of the second queue.
6. The method according to claim 4 or 5, characterized in that The method further comprises: After the second event is processed, the third event is processed; During the processing of the third event, detecting whether there is a fourth event in the first queue that needs to be processed in a timely manner; If it is detected that a fourth event that needs to be processed in a timely manner exists in the first queue, the processing of the third event is interrupted and the fourth event is processed.
7. The method according to any one of claims 1 to 6, characterized in that The first event includes N sub-events, where N is an integer greater than or equal to 2. During the processing of the first event, detecting whether there is a second event in the first queue that needs to be processed promptly includes: A detection step is performed once in the processing interval between every two adjacent sub-events in the N sub-events, wherein the detection step is used to detect whether there is a second event in the first queue that needs to be processed in a timely manner, and the processing interval includes the time period from the end time of processing of the previous sub-event to the start time of processing of the next sub-event.
8. The method according to claim 7, characterized in that The N sub-events are the N sub-events obtained by dividing the first event according to function or duration; wherein, each sub-event of the N sub-events obtained by functional division is used to implement a different function, and the processing time of each sub-event of the N sub-events obtained by duration is T / N, where T is the total processing time of the first event.
9. The method according to any one of claims 1 to 8, characterized in that The event queue further includes a third queue, the priority of the third queue is higher than the priority of the first queue, and the method further includes: During the processing of the second event, detecting whether there is a fifth event in the third queue that needs to be processed in a timely manner; If it is detected that a fifth event that needs to be processed in a timely manner exists in the third queue, the processing of the second event is interrupted and the fifth event is processed.
10. The method according to any one of claims 1 to 9, characterized in that The event queue further includes a fourth queue, the priority of the fourth queue being higher than the priority of the first queue. During the processing of the first event, detecting whether there is a second event that needs to be processed in a timely manner in the first queue includes: During the processing of the first event, detecting whether there is a sixth event that needs to be processed in a timely manner in the fourth queue; If the sixth event that needs to be processed in time does not exist in the fourth queue, it is detected whether the second event that needs to be processed in time exists in the first queue.
11. The method according to claim 10, characterized in that The method further comprises: If there is a sixth event that needs to be processed in time in the fourth queue, interrupting the first event and processing the sixth event; After the sixth event is processed, detecting whether there is a second event in the first queue that needs to be processed in a timely manner; If it is detected that a second event that needs to be processed in a timely manner exists in the first queue, the second event is processed.
12. The method according to any one of claims 1 to 11, characterized in that The processing of the second event includes: The second event is processed based on the processed portion of the first event.
13. The method according to claim 12, characterized in that The first event is used to obtain a display element in a target interface of the first application, the processed portion of the first event includes the obtained first display element, the second event is an interface refresh event, and processing the second event according to the processed portion of the first event includes: According to the first display element, the target interface is displayed, and the target interface includes the first display element.
14. The method according to claim 13, characterized in that The method further comprises: After the second event is processed, a seventh event is processed, where the seventh event includes an unprocessed portion of the first event and is used to obtain a second display element in the target interface; During the processing of the seventh event, it is detected that an eighth event that needs to be processed in a timely manner exists in the first queue, and the eighth event is an interface refresh event; If the processing time of the seventh event is less than a threshold, after the seventh event is processed, the eighth event is processed according to the processing result of the seventh event.
15. The method according to claim 14, characterized in that The processing result of the seventh event includes the acquired second display element, and processing the eighth event according to the processing result of the seventh event includes: Refresh the target interface according to the second display element, where the target interface includes the second display element.
16. The method according to claim 14 or 15, characterized in that The method further comprises: If the processing time of the seventh event is greater than or equal to the threshold, the processing of the seventh event is interrupted, and the eighth event is processed according to the processed part of the seventh event.
17. The method according to any one of claims 13 to 16, characterized in that: The first event is used to obtain display elements in the target interface from a local database or a server.
18. An electronic device, characterized in that: Used to perform the method according to any one of claims 1 to 17.
19. A computer-readable storage medium, characterized in that The computer-readable storage medium is used to store a computer program, and when the computer program is run on a computer, the computer is caused to perform the method according to any one of claims 1 to 17.
20. A computer program product, characterized in that The method comprises a computer program which, when run on a computer, causes the computer to perform the method according to any one of claims 1 to 17.
Citation Information
Patent Citations
Processing method and device for application lag and electronic equipment
CN111443957A
Memory allocation method and device, terminal equipment and storage medium
CN116048774A
Display method and device, electronic equipment and storage medium
CN118672437A
Device for managing event and computer readable recording medium recording program
JP2000137621A
Event processing method and apparatus
WO2022141297A1