In-application event transfer method
By introducing EventCenter components, the event delivery logic is decoupled, and the cumbersome and error-prone event delivery process in the existing technology is solved, and an efficient and easy-to-maintain event delivery mechanism is realized, which improves development efficiency and system stability.
Patent Information
- Application Number
- CN202411147254.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-11-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The lack of unified event delivery standards in the prior art makes the event delivery process cumbersome, time-consuming and error-prone. The high coupling and complex logic make it difficult to maintain and expand the code, reducing development efficiency and system stability.
Introduce EventCenter as the core component of event delivery, through event registration, listening and triggering, the event delivery logic is decoupled from the function page, and a global thread-safe Map collection is used to store event types and listener lists, providing registration interfaces and triggering methods. Use asynchronous processing mechanism to avoid main thread blocking.
It significantly improves development efficiency and code stability, reduces maintenance costs and system crash risks, improves user experience and system response speed, and enhances scalability and code comprehensibility.
Smart Images

Figure CN119046031A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of information processing, and in particular to an in-application event transmission method. Background Art
[0002] Apps running on mobile terminals often need to transfer events between different functional pages, for example:
[0003] After the function page PageA completes the operation of modifying the product name, it needs to assemble the modified product name, product ID, operator, operation time and other information into an event and pass it to the function page PageB that needs the above information. After the function page PageB listens to the event, it performs the corresponding logical operation or refreshes the page to display the latest product name and other content.
[0004] The existing technology lacks a unified maintenance standard for the assembly of such events, which results in a cumbersome, time-consuming and labor-intensive implementation process, high development costs, and prone to errors. This is specifically reflected in the following aspects:
[0005] Lack of unified standards: Different teams or developers may use different methods to implement event delivery, resulting in inconsistent code styles and difficulty in unified maintenance.
[0006] High coupling: Event delivery logic is often tightly coupled with the functional page. When a page changes, it may be necessary to modify the code of multiple related pages at the same time, increasing development complexity.
[0007] Inefficiency and high error rate: Manual management of event monitoring and triggering is prone to errors, and as the application scale expands, the efficiency of event delivery will gradually decrease.
[0008] Poor maintainability: Complex event delivery logic makes the code difficult to understand and maintain, increasing the difficulty of subsequent modification and expansion.
[0009] The information disclosed in this background technology section is only intended to deepen the understanding of the overall background technology of the present invention, and should not be regarded as acknowledging or suggesting in any form that the information constitutes the prior art already known to those skilled in the art. Summary of the invention
[0010] In view of the defects existing in the prior art, the purpose of the present invention is to provide an in-application event delivery method, which introduces EventCenter as the core component of event delivery to realize event registration, monitoring and triggering, and decouple event delivery logic from functional pages; this method is unified, efficient and easy to maintain, and can improve development efficiency and code stability.
[0011] In order to achieve the above purpose, the technical solution adopted by the present invention is:
[0012] An in-application event delivery method, characterized by comprising:
[0013] Create an event dispatch center EventCenter as the core component of event delivery, which includes: event registration, event monitoring, event triggering, and event delivery;
[0014] The event dispatch center EventCenter maintains a global, thread-safe Map collection to store the mapping relationship between event types and listener lists;
[0015] The event type includes: event name and unique identifier key;
[0016] The listener list contains all the listener objects registered for the event type;
[0017] The event dispatch center EventCenter provides a public registration interface, allowing function pages to register event listeners;
[0018] The event dispatch center EventCenter provides the trigger method trigger as an event trigger interface, which receives the event type and event data as parameters.
[0019] Based on the above technical solution, when registering, you need to specify the event type and the corresponding listener object.
[0020] Based on the above technical solution, after verification by the event dispatch center EventCenter, the listener is added to the listener list of the corresponding event type.
[0021] On the basis of the above technical solution, inside the trigger method trigger, EventCenter searches for the corresponding listener list according to the event type, then traverses the list, calls the processing function of the listener in sequence, and passes in the event data.
[0022] Based on the above technical solution, the event scheduling center EventCenter adopts an asynchronous processing mechanism. When an event is triggered, the event scheduling center EventCenter submits the processing logic of the listener to the thread pool or asynchronous task queue for execution to avoid blocking the main thread.
[0023] Based on the above technical solution, when a function page needs to pass an event Event to another function page, the trigger method trigger of the event scheduling center EventCenter is called to match and pass the event Event information through the unique identifier key registered in the Map collection of the other function page.
[0024] The in-application event transmission method described in the present invention has the following beneficial effects:
[0025] Significantly improve development efficiency: By encapsulating the event delivery logic in EventCenter, the function page does not need to worry about the complex delivery process, but only needs to focus on the implementation of business logic, which greatly improves development efficiency.
[0026] Reduce maintenance costs: The unified EventCenter manages all event monitoring and triggering, making the code structure clear, easy to understand and maintain. When the system is upgraded or the function is adjusted, only the relevant configuration in EventCenter needs to be modified, without modifying each function page one by one, which greatly reduces the maintenance cost.
[0027] Enhanced system stability: Since the event delivery process is strictly controlled in EventCenter, it reduces problems caused by delivery errors or omissions, and improves the overall stability of the system. At the same time, the decoupling design weakens the dependency between functional pages, reducing the risk of system crashes caused by a page error.
[0028] Improve user experience: The efficient event transmission mechanism ensures timely and accurate synchronization of information between pages, improving the application's response speed and user experience. For example, in e-commerce applications, real-time updates of product information enable users to obtain the latest product status in a timely manner, increasing shopping satisfaction.
[0029] Enhanced scalability: The in-application event delivery method of the present invention has good scalability. As applications continue to develop, new function pages can be easily connected to the existing system by registering monitoring and triggering events, without the need to significantly modify the existing architecture. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The present invention has the following accompanying drawings:
[0031] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0032] Figure 1 A flowchart of a first embodiment of a method for delivering an event within an application according to the present invention. DETAILED DESCRIPTION
[0033] The present invention is further described in detail below in conjunction with the accompanying drawings. The detailed description is an explanation made in conjunction with the exemplary embodiments of the present invention, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0034] like Figure 1 As shown, the present invention provides an in-application event transmission method, comprising:
[0035] Create an event dispatch center EventCenter as the core component of event delivery, which includes: event registration, event monitoring, event triggering, and event delivery;
[0036] The event dispatch center EventCenter maintains a global, thread-safe Map collection to store the mapping relationship between event types and listener lists;
[0037] The event type includes: event name and unique identifier key;
[0038] The listener list contains all the listener objects registered for the event type;
[0039] The event dispatch center EventCenter provides a public registration interface, allowing function pages to register event listeners;
[0040] The event dispatch center EventCenter provides the trigger method trigger as an event trigger interface, which receives the event type and event data as parameters.
[0041] The core component of this method is the event dispatch center EventCenter, whose main functions include:
[0042] EventCenter, the event dispatch center, is the core component of event delivery and is responsible for event registration, monitoring, triggering, and delivery.
[0043] This embodiment adopts the following event storage mechanism: the event scheduling center EventCenter maintains a global, thread-safe Map collection internally to store event types and their corresponding listener lists; the event type includes the event name and its unique identifier key; the listener list contains all listener objects registered for a specific event type.
[0044] The public interfaces of this embodiment are as follows:
[0045] Registration interface: allows function pages to register event listeners.
[0046] Trigger method: Provides a trigger method as an event trigger interface, receiving event type and event data as parameters.
[0047] This method provides a centralized, thread-safe and flexible event delivery mechanism. Through the unified management of EventCenter, it realizes the decoupling of function pages and event processing logic, enhances the modularity and scalability of the application, simplifies the debugging and maintenance process, and improves the stability and development efficiency of the system.
[0048] Based on the above technical solution, when registering, you need to specify the event type and the corresponding listener object.
[0049] Based on the above technical solution, after verification by the event dispatch center EventCenter, the listener is added to the listener list of the corresponding event type.
[0050] On the basis of the above technical solution, inside the trigger method trigger, EventCenter searches for the corresponding listener list according to the event type, then traverses the list, calls the processing function of the listener in sequence, and passes in the event data.
[0051] Based on the above technical solution, the event scheduling center EventCenter adopts an asynchronous processing mechanism. When an event is triggered, the event scheduling center EventCenter submits the processing logic of the listener to the thread pool or asynchronous task queue for execution to avoid blocking the main thread.
[0052] Based on the above technical solution, when a function page needs to pass an event Event to another function page, the trigger method trigger of the event scheduling center EventCenter is called to match and pass the event Event information through the unique identifier key registered in the Map collection of the other function page.
[0053] For example: the unique identifier key of the function page PageA registered in the Map collection is PageA_keyA; when the function page PageB needs to pass the event Event to the function page PageA, the trigger method trigger of the event dispatch center EventCenter is called to trigger the corresponding listener, match the unique identifier PageA_keyA of the function page PageA, and pass the event Event information. The function page PageA only needs to consider the need to handle specific events, and the function page PageB only needs to trigger the event transmission in a specific scenario. The event is decoupled from the function page, and the cumbersome transmission process is encapsulated in the event dispatch center EventCenter, which improves development efficiency.
[0054] The contents not described in detail in this specification belong to the prior art known to professional and technical personnel in this field.
[0055] The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiment. Any equivalent modifications or changes made by those skilled in the art based on the contents disclosed by the present invention should be included in the protection scope recorded in the claims.
Claims
1. A method for delivering events within an application. It is characterized in that include: Create an event dispatch center EventCenter as the core component of event delivery, which includes: event registration, event monitoring, event triggering, and event delivery; The event dispatch center EventCenter maintains a global, thread-safe Map collection to store the mapping relationship between event types and listener lists; The event type includes: event name and unique identifier key; The listener list contains all the listener objects registered for the event type; The event dispatch center EventCenter provides a public registration interface, allowing function pages to register event listeners; The event dispatch center EventCenter provides the trigger method trigger as an event trigger interface, which receives the event type and event data as parameters.
2. The method for delivering an event within an application as claimed in claim 1, It is characterized in that When registering, you need to specify the event type and the corresponding listener object.
3. The method for delivering an event within an application as claimed in claim 1, It is characterized in that After verification by the EventCenter, the event dispatch center adds the listener to the listener list of the corresponding event type.
4. The method for delivering an event in an application according to claim 1, It is characterized in that Inside the trigger method, EventCenter looks up the corresponding listener list based on the event type, then traverses the list, calls the listener's processing function in turn, and passes in the event data.
5. The method for delivering an event within an application as claimed in claim 1, It is characterized in that The event dispatch center EventCenter adopts an asynchronous processing mechanism. When an event is triggered, the event dispatch center EventCenter submits the processing logic of the listener to the thread pool or asynchronous task queue for execution to avoid blocking the main thread.
6. The method for delivering an event within an application as claimed in claim 1, It is characterized in that When a function page needs to pass an event Event to another function page, the trigger method trigger of the event scheduling center EventCenter is called to match and pass the event Event information through the unique identifier key registered in the Map collection of the other function page.
Citation Information
Cited By
Multi-window-based data storage management and control method, device, electronic equipment and system
CN121188305A
