Communication method between Android modularized modules

By using the global Map and class loading mechanism in the Android component-based public base library, the flexibility and maintenance difficulty of communication between components are solved, efficient inter-component communication is achieved, the interaction process is simplified and the cost is reduced.

CN118714218APending Publication Date: 2024-09-27SICHUAN HONGMEI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410746484.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-11
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

There are problems with the communication methods between Android component modules. Existing technologies such as EventBus, broadcast and ARouter are difficult to maintain and perform, and it is difficult to achieve flexible and efficient communication between components.

Method used

By providing a global Map in the public base library of Android components to store routing information, using the class loading mechanism and communication manager to achieve free communication between components, and registering class objects in routing information to establish communication channels.

Benefits of technology

It achieves flexible and efficient communication between components, reduces maintenance costs, avoids performance problems and security risks, and simplifies the interaction process between components.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118714218A
    Figure CN118714218A
Patent Text Reader

Abstract

The invention discloses a communication method between Android componentized modules, and relates to the technical field of Android mobile phone App development frameworks, the method is based on a class loading mechanism in Android componentization, routing information is stored through a global Map, and a communication manager enables each service component to freely establish a communication channel by means of a class object in the registered routing information. According to the scheme, a global Map is provided in a public basic library of Android componentization to manage each component, so that each component can communicate through a manager.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Android mobile phone App development framework, and more specifically to a communication method between Android componentized modules. Background Art

[0002] Android componentization is a software architecture pattern that usually decomposes an application into an app shell, a business component layer, and a common basic library. It aims to decompose large applications into multiple independent components so that each component can be independently developed, tested, debugged, and deployed. This pattern decomposes the application into independent functional units, each of which can be developed and maintained as an independent module. However, while componentization brings convenience, it also brings an important problem - communication between components. After becoming independent, the modules cannot communicate freely as before componentization. Before componentization, the application projects were all under the same project directory of the app, so the members could communicate according to normal rules, but after componentization, the business components will not be able to communicate directly with other components due to their independence. The following are the mainstream communication methods between Android componentized modules on the market:

[0003] 1. EventBus: EventBus is an event bus library based on the observer pattern, which can publish and subscribe events between different modules. By defining event classes and event processing methods, modules can communicate decoupled through the event bus. However, the abuse of EventBus will cause EventBus to fly all over the project source code, making it difficult to track the event transmission path and the maintenance cost is too high.

[0004] 2. Broadcast: Broadcast is a global communication method that can send broadcast messages within an application or between applications. However, broadcast should be used with caution because it is global and can easily lead to performance problems and security risks. In addition, after Android 8.0, all implicit broadcasts are not allowed to be received using static registration. Implicit broadcasts can only be received using dynamic registration, which makes the use of broadcast more cumbersome.

[0005] 3. Reflection: As long as you can get the Class object, you can do whatever you want. But this method is relatively "violent" and not beautiful enough.

[0006] ARouter: Scan and process annotations during compilation through APT (Annotation Processing Tool) to add routing tables. In fact, the essence of communication is also reflection. However, although ARouter provides rich functions, each modification of routing configuration requires recompiling the entire project. For large projects, a large number of routing rules need to be configured, which increases the difficulty of maintenance and requires a certain learning cost. Summary of the invention

[0007] The purpose of the present invention is to provide a communication method between Android componentized modules in order to solve the problems in the background technology. The present invention provides a global Map in the common basic library of Android componentized modules to manage each component so that each component can communicate through a manager.

[0008] In order to achieve the above object, the present invention adopts the following technical solutions:

[0009] A communication method between Android componentized modules. The method is based on a class loading mechanism in Android componentization, stores routing information through a global Map, and a communication manager enables each business component to freely establish a communication channel through class objects in the registered routing information.

[0010] In some embodiments, the routing information is stored in a global Map, and the communication manager enables each service component to freely establish a communication channel by using the class object in the registered routing information, including:

[0011] Componentize the Android project and create a data class PathModule in the public base library that contains path names and class objects;

[0012] Create a singleton class RecordPathManager in the common base library to manage communication between components;

[0013] Create default public inter-component communication methods in RecordPathManager;

[0014] In the Application of the project's app shell project, register the component member information as routing information in the RecordPathManager;

[0015] When interaction is required among components, the corresponding methods are called through the singleton object to communicate across components, or a one-way communication channel is established by obtaining the class object.

[0016] In some embodiments, the RecordPathManager contains a storage group name, a Map of PathModules, methods for storing class objects in the Map, and methods for retrieving class objects from the Map.

[0017] In some embodiments, in a project of Android componentized architecture, an application is divided into an app shell, a business component layer, and a public basic library, and a global Map is created in the public basic library for storing routing information.

[0018] In some embodiments, the key of the global Map is the group name, and the value is a List. The type stored in the List is a data class that encapsulates the path name and the class object.

[0019] In some embodiments, a data class is defined in a common basic library and the global context Context is initialized. The data class includes a path name and a class object, and the data class serves as a carrier of routing information.

[0020] In some embodiments, a singleton class is created in a public base library as a communication manager, which is responsible for registering and obtaining routing information and providing a default public cross-component communication method.

[0021] In some embodiments, the registration of routing information is completed when the application is initialized, that is, the information of the business component members that need to communicate is registered through the communication manager in the Application of the app shell project, so that the registration of routing information is completed before it is used in the business component. Compared with the prior art, the present invention has the following beneficial effects:

[0022] Use the global Map method to store routing information (including group name, path name and class object), create a manager class in the public basic library to manage routing communication, and complete the registration in the app shell project so that the application can complete the registration when it is initialized; during communication, obtain the class object that needs to communicate through the manager in the business component to establish one-way communication. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 : Android componentized module communication structure diagram;

[0024] Figure 2 : Component communication data flow diagram;

[0025] Figure 3 : Broadcast communication structure diagram;

[0026] Figure 4 : EventBus communication structure diagram. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the embodiments of the present application will be described in more detail below in conjunction with the drawings in the preferred embodiments of the present application. In the drawings, the same or similar reference numerals throughout represent the same or similar parts or parts with the same or similar functions. The described embodiments are part of the embodiments of the present application, not all of the embodiments. The embodiments described below with reference to the drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limitations on the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0028] The embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0029] The following will be combined with the figures to describe in detail a communication method between Android componentized modules involved in the embodiment of the present application. It is worth noting that the following embodiments are only used to explain the present application and do not constitute a limitation on the present application.

[0030] Embodiment 1:

[0031] The present invention provides a global Map in the Android componentized public basic library to manage various components, so that various components can communicate through a manager.

[0032] like Figure 1-2 As shown, a communication method between Android componentized modules includes the following steps:

[0033] First, build the Android project in components and create a data class PathModule in the public base library that contains path names and class objects;

[0034] Secondly, create a singleton class RecordPathManager in the public base library to manage communication between components. RecordPathManager needs to contain a storage group name (a component may have multiple members participating in communication, so it is necessary to group by component) and a Map of PathModule, as well as methods for storing class objects in the Map and retrieving class objects from the Map.

[0035] Then, create a default public method for inter-component communication in RecordPathManager, such as encapsulating a default custom Activity jump method (setting jump parameters, default jump animation, etc.);

[0036] Next, register the component member information as routing information in the RecordPathManager in the Application of the project's app shell project, so that the routing information can be registered when the application is started and initialized;

[0037] Finally, when interaction is required among components, corresponding methods can be called through the singleton object to communicate across components, or a one-way communication channel can be established by obtaining the class object.

[0038] like Figure 1 As shown in the figure, the Android App project is divided into app shell project, business component layer and public basic library through componentization.

[0039] 1. Define a data class PathModule containing path names and class objects in the public basic library, and complete the initialization of the global context Context;

[0040] 2. Define a singleton class RecordPathManager in the public base library as a manager to manage component member communications;

[0041] 3. Create a global Map in RecordPathManager to store component members that need to communicate, and define two methods as methods for registering with the manager and obtaining PathModule objects;

[0042] 4. Define the methods required for interaction between other components in RecordPathManager for cross-component interaction in business components, such as providing a default method for Activity jump;

[0043] 5. Register routing information, such as Figure 1 The dotted arrow between the app shell project and the communication manager indicates that the communication component member information is registered through RecordPathManager in the Application of the app shell project and stored in the global Map as routing information;

[0044] When cross-component communication is required in each component, RecordPathManager is used to obtain the member class object that needs to be communicated, and then normal communication can be carried out. Figure 2 As shown, after business component 2 obtains the class object of business component 1 from the manager, it can establish a communication channel from business component 2 to business component 1; similarly, the communication channel from business component 1 to business component 2 is also established in the same way. Cross-component interaction can also be achieved through the public methods provided by the communication manager.

[0045] See also Figure 2, the communication process of the present invention is as follows:

[0046] 1. Registration: Manually register the communication component member information in the program initialization code block.

[0047] 2. Establish a communication channel: The sender obtains the class object of the receiver from the communication manager by specifying the group and path name, and then establishes a unidirectional communication channel from the sender to the receiver.

[0048] 3. Communication: After establishing the communication channel, the sender can make corresponding communications to the receiver.

[0049] See also Figure 3 , which is the Android broadcast communication structure diagram. Broadcast is a system-level message delivery mechanism. The following is the process of using broadcast for componentized communication:

[0050] 1. Broadcast sender: The component calls the broadcast sending method provided by the system to send the message that needs to be notified to other components in the form of broadcast.

[0051] 2. Broadcast receiver registration: Other components declare their interest in one or more broadcasts by registering broadcast receivers in AndroidManifest.xml or dynamically registering broadcast receivers in code.

[0052] 3. Broadcast receiver monitoring: Once a broadcast is sent, the system will distribute the broadcast to all broadcast receivers registered for the corresponding type. After receiving the broadcast, the receiver can perform corresponding logical operations.

[0053] 4. Broadcast processing: After receiving the broadcast, the broadcast receiver can execute corresponding logic based on the information carried by the broadcast.

[0054] like Figure 4 The following is a diagram of the EventBus communication structure. The communication principle is mainly based on the observer mode. The communication process of EventBus is as follows:

[0055] 1. Registration: When a component needs to receive events, it registers on EventBus to indicate that it is an event subscriber.

[0056] 2. Release: When a component has an event to be released, the event is released through EventBus.

[0057] 3. Event processing: EventBus distributes events to all components that have subscribed to the event type according to the event type, thereby realizing event delivery and processing.

[0058] The core of this invention is the use of the class loading mechanism, which enables communication to be completed through class objects, which is similar to the communication method implemented by reflection. However, this invention has been beautified and encapsulated on this basis. The member information of the components that need to communicate is registered and stored through the global Map, and managed by the manager, which fully beautifies and simplifies the usage. ARouter also manages the routing through registration, but it completes the registration in the compiler through APT, and recompilation is required if the configuration needs to be changed.

[0059] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A communication method between Android component modules, It is characterized in that This method is based on the class loading mechanism in Android componentization. The routing information is stored in the global Map. The communication manager enables each business component to freely establish a communication channel through the class objects in the registered routing information.

2. According to claim 1, a communication method between Android componentized modules, It is characterized in that By storing routing information in the global Map, the communication manager enables each business component to freely establish a communication channel through the class object in the registered routing information, including: Componentize the Android project and create a data class PathModule in the public base library that contains path names and class objects; Create a singleton class RecordPathManager in the common base library to manage communication between components; Create default public inter-component communication methods in RecordPathManager; In the Application of the project's app shell project, register the component member information as routing information in the RecordPathManager; When interaction is required among components, the corresponding methods are called through the singleton object to communicate across components, or a one-way communication channel is established by obtaining the class object.

3. According to claim 1, a communication method between Android componentized modules, It is characterized in that The RecordPathManager contains a storage group name, a Map of PathModules, and methods for storing class objects in the Map and retrieving class objects from the Map.

4. According to claim 1, a communication method between Android componentized modules, It is characterized in that In Android component-based architecture projects, the application is divided into an app shell, a business component layer, and a public base library. A global Map is created in the public base library to store routing information.

5. According to claim 1, a communication method between Android componentized modules, It is characterized in that The key of the global Map is the group name, and the value is a List. The type stored in the List is a data class that encapsulates the path name and class object.

6. According to claim 4, a communication method between Android component modules, It is characterized in that A data class is defined in the public basic library and the global context Context is initialized. The data class contains the path name and the class object. The data class serves as the carrier of the routing information.

7. The communication method between Android componentized modules according to claim 1, It is characterized in that Create a singleton class in the public base library as a communication manager, which is responsible for registering and obtaining routing information and providing a default public cross-component communication method.

8. The communication method between Android componentized modules according to claim 1, It is characterized in that The registration of routing information is completed when the application is initialized, that is, the information of the business component members that need to communicate is registered through the communication manager in the Application of the app shell project, so that the registration of routing information is completed before it is used in the business component.