WO2019010928A1 - 一种多Fragment之间的通信方法及系统 - Google Patents
一种多Fragment之间的通信方法及系统 Download PDFInfo
- Publication number
- WO2019010928A1 WO2019010928A1 PCT/CN2017/120152 CN2017120152W WO2019010928A1 WO 2019010928 A1 WO2019010928 A1 WO 2019010928A1 CN 2017120152 W CN2017120152 W CN 2017120152W WO 2019010928 A1 WO2019010928 A1 WO 2019010928A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- message
- fragment
- fragments
- interface
- controller
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/451—Execution arrangements for user interfaces
Definitions
- the present invention relates to the field of communication technologies, and in particular, to a communication method and system between multiple Fragment.
- Fragment is a fragment element in the entire interface, which can be understood as Fragment as part of the interface.
- An interface can load one or more fragments.
- the entire interface contains three tab elements.
- Each tab element is a page in the interface.
- Tab pages can be switched between each other.
- a tab page can be switched by a Fragment.
- a Fragment can control the business logic of a page, and multiple Fragment can separate and separate the business logic of each page, which is convenient for later maintenance.
- the present invention provides a communication method and system between multiple Fragment that overcomes the above problems or at least partially solves the above problems.
- a communication method between multiple Fragments including:
- the message controller forwards the message of the source Fragment to the destination Fragment.
- the invention has the beneficial effects that: configuring a message manager for all the Fragment in the interface, and implementing a Fragment to send a message to another Fragment by means of the message controller to avoid confusion of direct communication between the multiple Fragments;
- a message manager for all the Fragment in the interface
- implementing a Fragment to send a message to another Fragment by means of the message controller to avoid confusion of direct communication between the multiple Fragments
- the source Fragment sends a message to the destination Fragment having a nested relationship, it is directly controlled by the message.
- the device forwards to the destination Fragment without passing through the first-level Fragment, avoiding the complicated communication problem caused by the need to send messages layer by layer.
- the present invention can also be improved as follows.
- step S2 further includes:
- a command interface is defined for each Fragment, and an interface function is defined for the command interface, and the interface function includes at least a message command word and a message body parameter.
- step S2 further includes:
- step S2 further includes:
- the message controller When the message controller receives the message sent by the source Fragment, the message is sent to the destination Fragment in a broadcast manner or in a peer-to-peer manner.
- step S2 further includes:
- the message controller When the message controller receives the message sent by the source fragment, the message is broadcast to the Fragment registered with the message controller;
- the Fragment that receives the message determines whether the message needs to be processed according to the message command word in the message.
- step S2 further includes:
- the message controller traverses all the Fragment objects in the object collection in a round-robin manner
- an interface function in the Fragment object is called, and the message is delivered to an interface function of the Fragment object, and the interface function determines whether the message needs to be processed according to the message command word in the message.
- the message further includes a destination Fragment identifier
- the step S2 further includes:
- the message controller receives the message sent by the source Fragment, and forwards the message to the destination Fragment according to the destination Fragment identifier in the message.
- a communication system between multiple Fragments comprising:
- a configuration module configured to configure a message controller for all the Fragments in the interface
- a registration module configured to register all the Fragment in the message controller
- the forwarding module is configured to forward the message of the source Fragment to the destination Fragment by the message controller based on the command interface defined for each Fragment and its interface function.
- an apparatus for a communication method between multiple Fragments including a processor, a memory, and a bus;
- the processor and the memory complete communication with each other through the bus;
- the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the various implementation methods described above.
- a non-transitory computer readable storage medium storing computer instructions that cause the computer to perform the various implementation methods described above.
- FIG. 1 is a flow chart of a communication method between multiple Fragments according to an embodiment of the present invention
- FIG. 2 is a block diagram showing a communication system connection between multiple Fragments according to another embodiment of the present invention.
- FIG. 3 is a block diagram showing the overall connection of a communication system between multiple Fragments according to still another embodiment of the present invention.
- FIG. 4 is a block diagram showing the internal connection of a message controller according to still another embodiment of the present invention.
- FIG. 5 is a block diagram of an electronic device connection according to an embodiment of the present invention.
- a communication method between multiple Fragment including: S1, configuring a message controller for all Fragment fragments in an interface, and registering all Fragments in the message controller; S2 Based on the command interface defined for each Fragment and its interface function, the message controller forwards the message of the source Fragment to the destination Fragment.
- Fragment can be understood as a fragment element, that is, an interface can contain multiple fragment elements.
- a Fragment can manage the business logic of a page. Multiple Fragments can separate and separate the business logic of each page. Communication is required between each Fragment. The traditional way is to directly communicate between Fragment, that is, the source Fragment directly sends a message to the destination Fragment.
- the present embodiment provides a simple communication method between a plurality of Fragments.
- a communication protocol for communication between multiple Fragment is designed, and subsequent Fragments follow this protocol to communicate, specifically designing between multiple Fragment
- the communication protocol is to define command interfaces and interface functions for each Fragment in the interface.
- a message controller is configured for all the Fragments in the interface, wherein the message controller is used to control all the Fragments.
- the message controller based on the command interface and interface function defined for each Fragment, the message controller mainly implements forwarding of messages between multiple Fragments.
- the Fragment that sends the message is called the source Fragment
- the Fragment that receives the message is called the destination Fragment.
- the source Fragment first sends a message to the message controller, and the message controller forwards the message to the destination Fragment.
- the destination Fragment needs to receive the message from the message controller and needs to register with the message controller. Only the Fragment registered in the message controller can receive the message forwarded by the message controller.
- communication is implemented based on the above communication protocol.
- all the Fragment configuration message managers in the interface are implemented by the message controller to implement a Fragment to send a message to another Fragment to avoid confusion of direct communication between multiple Fragments; and when between multiple Fragments
- the message controller directly forwards the message to the destination. Fragment, without the need to pass the first-level Fragment, avoids the complicated communication problems that need to be sent layer by layer.
- the step S2 further includes: defining a command interface for each Fragment, and defining an interface function for the command interface, where the interface function includes at least a message command word. And message body parameters.
- the designed communication protocol In order to be compatible with all messages, the designed communication protocol can be divided into two parts. The first part is the message command word, which is mainly used. To indicate the type of message, the second part is the message body, which is the specific content of the message.
- the program code of the designed command interface is as follows:
- Interface indicates that the protocol is an interface protocol
- IMessage indicates the name of the interface protocol
- onMessage indicates the interface function contained in the interface protocol, and its return value is of type void, that is, there is no return value.
- the interface function contains two parameter information, one is a String (string) type command, command indicates the message command word issued, and the other parameter is the Object type message. The reason is designed as Object type to be able to All types of messages are received through this interface function.
- each parameter in the above interface function has a prefix @NoNullable, indicating that the parameter passed to the interface function cannot be null (null), in order to ensure that the parameter is not empty.
- the communication interface design is described by the above programmed language, and any message can be transmitted through the command and message mode.
- the Fragment needs to follow the communication protocol designed above.
- the above programmatic representation is that the Fragment needs to inherit the IMessage interface and overwrite the onMessage method. After such processing, the fragment is a Fragment that inherits from the IMessage interface, and has the ability to receive messages sent by the IMessage interface.
- the Fragment must receive the message forwarded by the message controller, and must register with the message controller. Only the Fragment registered with the message controller can receive the message distributed by the message controller. Among them, the specific registration process is: Fragment is a class, each class has a constructor, and registration is implemented in the constructor of the Fragment to ensure that the Fragment is actively registered in the message controller when it is instantiated.
- the message registrar register (this.fragment) in the message controller is called in the constructor of the Fragment, and the Fragment object is registered in the message controller.
- all the Fragments registered in the message controller are in a peer relationship, that is, all the Fragments belong to an equal relationship, and multiple Fragments in the existing existence have a nested relationship, that is, multiple Fragments have a hierarchical relationship.
- this hierarchical relationship is reported by registering with the message controller, and all the Fragments registered in the message controller are in a peer relationship.
- the step S2 further includes: maintaining, for all the Fragments registered to the message controller, a Fragment object for storing all the registrations in the message controller. Collection of objects.
- the step S2 further includes: when the message controller receives the message sent by the source fragment, the message is broadcasted or peer-to-peer. Send to the destination Fragment.
- the message controller When the message controller receives the message sent by the source Fragment and forwards it to the destination Fragment, the message controller can forward the message in two ways, one is to broadcast the message to the destination Fragment, and the other is to pass the peer-to-peer.
- the way to forward messages to the destination Fragment enables flexible distribution in a variety of ways.
- step S2 further includes: when the message controller receives the message sent by the source fragment, and broadcasts the message to the Fragment registered with the message controller; The Fragment that receives the message determines whether the message needs to be processed according to the message command word in the message.
- the message controller when the message controller forwards the message to the destination Fragment, it may be broadcast or peer-to-peer.
- the message controller sends the message in a broadcast manner, the message controller broadcasts the message to the Fragment registered in the message controller when receiving the message of the Fragment, wherein the message includes the message command word and the message body.
- the Fragment that receives the message determines whether the message is a message required by itself according to the message command word in the message, and if it is a required message, acquires the message and processes it.
- the specific process of the message controller broadcasting the message to the Fragment registered in the message controller is: the message controller traverses all the Fragment objects in the object set by means of a for loop, and extracts the Fragment one by one from the object set. Each time a Fragment object is extracted, the interface function onMessage in the Fragment object is called, and the message received from the Fragment of the sent message is passed to the interface function onMessage of the Fragment object, and the interface function onMessage is based on the message command word in the message. Determine whether the message needs to be processed, so that the process of sending a message to another Fragment is completed by the forwarding of the message controller.
- the step S2 further comprises: the message controller receiving the message sent by the source Fragment, and forwarding the message to the destination Fragment according to the destination Fragment identifier in the message.
- the message controller forwards the message by means of a broadcast, and in this embodiment, the message controller forwards the message by means of a peer-to-peer. Specifically, when the message controller receives the message sent by the source Fragment, where the message includes the destination Fragment identifier that needs to send the message. The message controller forwards the message directly to the destination Fragment based on the destination Fragment identifier in the message.
- the message delivery in the solution is forwarded by the message controller, and is not a way of direct communication between the traditional Fragment, and the design method of forwarding the message through the message controller is All the Fragments registered in the message controller are in a peer-to-peer relationship.
- the source Fragment sends a message to the destination Fragment with a nested relationship, it is directly forwarded by the message controller to the destination Fragment, so that the message is sent and received with the Fragment.
- Hierarchical level is not related, and does not need to be passed through the first-level Fragment, avoiding the complicated communication problem caused by the need to send messages layer by layer.
- a communication system between multiple Fragments of another embodiment of the present invention including a configuration module 21, a registration module 22, and a message controller 23.
- the configuration module 21 is configured to configure a message controller for all the fragments in the interface.
- the registration module 22 is configured to register all the Fragments in the message controller.
- the forwarding module 23 is configured to forward, by the message controller, the message of the source Fragment to the destination Fragment based on the command interface defined for each Fragment and its interface function.
- the configuration module 21 is further configured to:
- a command interface is configured for each Fragment, and an interface function is defined for the command interface, where the interface function includes a message command word and a message body parameter.
- the communication system between multiple Fragments further includes a maintenance module 24 for maintaining a Fragment object for storing all registrations in the message controller for all Fragments registered to the message controller. Collection of objects.
- the message controller 23 is further specifically configured to:
- the message controller When the message controller receives the message sent by the source Fragment, it sends the message to the destination Fragment in a broadcast or peer-to-peer manner.
- the message controller 23 is also specifically used to:
- the message When receiving the message sent by the source Fragment, the message is broadcast to the Fragment registered with the message controller, so that the Fragment receiving the message determines whether the message needs to be processed according to the message command word in the message. .
- the message controller 23 includes a traversal unit 231 and a calling unit 232, wherein the traversing unit 231 is configured to traverse all of the Fragment objects in the object set in a round-robin manner.
- the calling unit 232 is configured to, when extracting a Fragment object, invoke an interface function in the Fragment object, and deliver the message to an interface function of the Fragment object, where the interface function determines according to a message command word in the message. Whether the message needs to be processed.
- an electronic device includes a processor 501, a memory 502, and a bus 503.
- the processor 501 and the memory 502 complete communication with each other through the bus 503. .
- the processor 501 is configured to invoke program instructions in the memory 502 to perform the methods provided by the foregoing method embodiments, for example, including: configuring a message controller for all Fragment fragments in the interface, and controlling the message All Fragments are registered, wherein all registered Fragments are in an equal relationship; based on the command interface defined for each Fragment and its interface function, the message controller forwards the source Fragment message to the destination Fragment.
- the invention discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions, the computer being capable of executing the corresponding implementation when the program instructions are executed by the computer
- the intelligent filtering control layout method provided by the example includes, for example, configuring a message controller for all Fragment fragments in the interface, and registering all the Fragment in the message controller, wherein all registered Fragments are in an equal relationship; For each command interface defined by each Fragment and its interface function, the message controller forwards the message of the source Fragment to the destination Fragment.
- the present invention also provides a non-transitory computer readable storage medium storing computer instructions for causing a computer to execute the smart layout control method provided by the corresponding embodiment, for example, including Configuring a message controller for all Fragment fragments in the interface, and registering all Fragments in the message controller, wherein all registered Fragments are in an equal relationship; based on the command interface defined for each Fragment and its interface function, The message of the source Fragment is forwarded by the message controller to the destination Fragment.
- the foregoing program may be stored in a computer readable storage medium, and the program is executed when executed.
- the foregoing steps include the steps of the foregoing method embodiments; and the foregoing storage medium includes: a medium that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.
- the invention provides a communication method and system between multiple Fragment, and configures a message manager for all Fragment in the interface, and the message controller performs forwarding to implement a Fragment to send a message to another Fragment to avoid multiple Fragment The confusion of direct communication; and when there is a nested relationship between multiple Fragments, since all the Fragments registered in the message controller in this embodiment are in a peer relationship, the source Fragment has a nested relationship.
- the message is sent by the Fragment, it is directly forwarded to the destination Fragment by the message controller, without the need to pass the Fragment of the first-level level, which avoids the complicated communication problem caused by the need to send messages layer by layer.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Computer And Data Communications (AREA)
- Information Transfer Between Computers (AREA)
Abstract
一种多Fragment之间的通信方法及系统,所述的方法包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment均处于平等关系(S1);基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment(S2)。所述方法为界面中所有的Fragment配置消息管理器,通过消息控制器进行转发的方式实现不同Fragment之间的通信,避免多个Fragment之间直接通信带来的混乱,以及当多个Fragment之间存在嵌套关系时,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。
Description
交叉引用
本申请引用于2017年7月10日提交的专利名称为“一种多Fragment之间的通信方法及系统”的第201710556420.1号中国专利申请,其通过引用被全部并入本申请。
本发明涉及通信技术领域,更具体地,涉及一种多Fragment之间的通信方法及系统。
在Android开发过程中,通常会涉及到界面相关的编程,Fragment为整个界面中的碎片元素,可以理解为Fragment为界面中的一部分。
一个界面可以装载一个或多个Fragment,比如,整个界面包含三个tab元素,每一个tab元素为界面中的一个页面,tab页面之间可以切换,一个tab页面的切换可以由一个Fragment来控制。在开发过程中,一个Fragment可以控制一个页面的业务逻辑,多个Fragment可以分离和独立各个页面的业务逻辑,方便后期维护。
多个Fragment之间需要进行通信,传统的方式是Fragment之间直接通信,这样如果Fragment的数量很多时,Fragment之间的通信会比较混乱,同时,若多个Fragment之间存在嵌套引用关系,则顶层的Fragment向最底层的Fragment发送消息时,需要通过各级的Fragment逐层进行转发,通信速度慢。
发明内容
本发明提供一种克服上述问题或者至少部分地解决上述问题的多Fragment之间的通信方法及系统。
根据本发明的第一个方面,提供一种多Fragment之间的通信方法,包括:
S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;
S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
本发明的有益效果为:为界面中所有的Fragment配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。
在上述技术方案的基础上,本发明还可以作如下改进。
进一步的,所述步骤S2进一步包括:
为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。
进一步的,所述步骤S2还包括:
对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。
进一步的,所述步骤S2进一步包括:
当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。
进一步的,所述步骤S2进一步包括:
当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;
接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。
进一步的,所述步骤S2进一步包括:
消息控制器通过循环的方式遍历对象集合中的所有Fragment对象;
每提取一个Fragment对象,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息进行处理。
进一步的,所述消息中还包括目的Fragment标识,所述步骤S2进一步包括:
消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。
根据本发明的第二个方面,还提供了一种多Fragment之间的通信系统,包括:
配置模块,用于为界面中的所有Fragment配置消息控制器;
注册模块,用于在所述消息控制器中注册所有的Fragment;
转发模块,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
根据本发明的第三个方面,提供了一种多Fragment之间的通信方法的设备,包括处理器(processor)、存储器(memory)和总线;
所述处理器和存储器通过所述总线完成相互间的通信;
所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行上述各实施方法。
根据本发明的第四个方面,提供了一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行上述各实施方法。
图1为本发明一个实施例的多Fragment之间的通信方法流程图;
图2为本发明另一个实施例的多Fragment之间的通信系统连接框图;
图3为本发明又一个实施例的多Fragment之间的通信系统的整体连接框图;
图4为本发明再一个实施例的消息控制器内部连接框图;
图5为本发明一个实施例的电子设备连接框图。
下面结合附图和实施例,对本发明的具体实施方式作进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。
参见图1,提供了本发明一个实施例的多Fragment之间的通信方法,包括:S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment;S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
在Android的开发过程中,通常会涉及到界面相关的编程,在一个界面经常会有多个Fragment,其中,Fragment可以理解为碎片元素,即一个界面中可以包含多个碎片元素。一个Fragment可以管理一个页面的业务逻辑,多个Fragment可以将各个页面的业务逻辑进行分离和独立。各个Fragment之间需要通信,传统的方式是Fragment之间直接通信,即源Fragment直接向目的Fragment发送消息。采用该种通信的方式,如果Fragment的数量很多时,Fragment之间的通信会比较混乱;同时,若多个Fragment之间存在嵌套引用关系,则顶层的Fragment向最底层的Fragment发送消息时,需要逐层进行转发,通信速度慢。
因此,本实施例为了解决上述的问题,为多个Fragment之间提供了一套简单的通信方法。在具体的实现过程中,为了实现多个Fragment之间的通信,设计多个Fragment之间进行通信的通信协议,后续的Fragment之间都遵循本协议来进行通信,具体设计多个Fragment之间的通信协议是,为界面中的每一个Fragment定义命令接口和接口函数。同时,为界面中的所有的Fragment配置消息控制器,其中,消息控制器用来对所有的Fragment 进行控制。在本实施例中,基于为每一个Fragment定义的命令接口和接口函数,消息控制器主要实现多个Fragment之间消息的转发。
在本实施例中,一个Fragment在向另一个Fragment发送消息时,为描述方便,发送消息的Fragment称为源Fragment,接收消息的Fragment称为目的Fragment。源Fragment先将消息发送给消息控制器,由消息控制器将消息转发给目的Fragment。目的Fragment要接收消息控制器中的消息,需要向消息控制器中进行注册,只有在消息控制器中注册过的Fragment,才能接收到消息控制器转发的消息。另外,在源Fragment与消息控制器以及消息控制器与目的Fragment之间通信的过程中,均是基于上述通信协议实现通信的。
本实施例为界面中所有的Fragment配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。
在上述实施例的基础上,本发明的一个实施例中,所述步骤S2进一步包括:为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。
在为多个Fragment之间设计通信协议的过程中,为每一个Fragment设计一套命令接口,为了能够兼容所有的消息,设计的通信协议可以分为两部分,第一部分为消息命令字,主要用来表示消息的类型,第二部分为消息体,也即消息的具体内容。设计的命令接口的程序代码如下:
其中interface表示该协议是一个接口协议,IMessage表示该接口协议的名称;onMessage表示该接口协议所包含的接口函数,它的返回值是void类型的,也就是说没有返回值。该接口函数包含有两个参数信息,其一是一个String(字符串)类型的command,command表示下发的消息命令字,另一个参数是Object类型的message,之所以设计成Object类型是为了能够通过该接口函数接收所有类型的消息。
通过观察,可以发现上述接口函数中的每一个参数都带有一个前缀@NoNullable,表明向接口函数中传递的参数不能为空(null),是为了确保参数的非空。
通过上述程序化的语言描述了通信接口设计,可以通过命令和消息的模式来进行任何消息的传递,Fragment为了能够接收消息,需要遵循上述设计的通信协议。上述程序化的展现即是Fragment需要继承IMessage接口,并且复写其中的onMessage方法。通过这样的处理后,fragment就是一个继承于IMessage接口的Fragment,也就具备了接收IMessage接口发送的消息的能力。
另外,Fragment要接收消息控制器转发的消息,必须向消息控制器进行注册,只有向消息控制器进行注册过的Fragment才能够接收消息控制器分发的消息。其中,具体的注册过程为:Fragment是一个类,每个类都有构造函数,在Fragment的构造函数中实施注册,就能够保证Fragment被实例化时,主动被注册到消息控制器中。
在Fragment的构造函数中调用消息控制器中的消息注册器register(this.fragment),将该Fragment对象注册到消息控制器中。其中,注册到消息控制器中的所有的Fragment都处于对等的关系,即所有的Fragment属于平等的关系,现有中的多个Fragment会存在嵌套关系,即多个Fragment是具有层级关系的,而在本实施例中,通过向消息控制器进行注册来消息这种层级关系,在消息控制器中注册过的所有的Fragment都处于对等的关系。
在上述各个实施例的基础上,本发明的另一个实施例中,所述步骤S2还包括:对于注册到消息控制器的所有Fragment,在消息控制器内维护一个 用来存放所有注册的Fragment对象的对象集合。
当界面中所有的Fragment都注册到消息控制器中后,在消息控制器中维护一个对象集合,该对象集合主要用来存放所有注册到消息控制器中的Fragment,以便后续消息控制器能够像Fragment分发消息。
在上述各个实施例的基础上,本发明的另一个实施例中,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。
在消息控制器接收到源Fragment发送的消息,向目的Fragment转发的过程中,消息控制器可以采用两种方式进行转发,一种是以广播的方式向目的Fragment转发消息,另一种是通过点对点的方式向目的Fragment转发消息,实现多种方式的灵活分发。
在上述各实施例的基础上,本发明的一个实施例中,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。
上述已经说明,在消息控制器向目的Fragment转发消息时,可以采用广播的方式或者点对点的方式。当消息控制器以广播的方式发送消息时,消息控制器接收到一个Fragment的消息时,向在消息控制器中注册过的Fragment广播该消息,其中,消息中包括消息命令字和消息体。接收到消息的Fragment根据消息中的消息命令字,来确定该消息是否为自身所需的消息,若是需要的消息,则获取该消息并进行处理。
其中,消息控制器向在消息控制器中注册过的Fragment广播消息的具体过程为:消息控制器通过for循环的方式遍历对象集合中的所有Fragment对象,并从对象集合中逐个提取Fragment。每提取一个Fragment对象,则调用该Fragment对象中的接口函数onMessage,并将从发送消息的Fragment接收的消息传递到该Fragment对象的接口函数onMessage中,由该接口函数onMessage根据消息中的消息命令字确定是否需要对该消息进行处理,这样就通过消息控制器的转发完成了一个Fragment向另一个Fragment发送消 息的过程。
在本发明的另一个实施例中,所述步骤S2进一步包括:消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。
上述实施例消息控制器是通过广播的方式来转发消息的,而本实施例中消息控制器是通过点对点的方式来转发消息的。具体为,当消息控制器接收到源Fragment发送的消息时,其中,消息中包括需要发送消息的目的Fragment标识。消息控制器根据消息中的目的Fragment标识,将消息直接转发给目的Fragment。
通过上述两种方式,可以看出本方案中消息的传递是通过消息控制器来进行转发的,并不是传统的Fragment之间直接通信的方式,通过消息控制器对消息进行转发的设计方式,由于在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,使得消息的收发与Fragment所在的层级无关联性,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。
参见图2,提供了本发明另一个实施例的多Fragment之间的通信系统,包括配置模块21、注册模块22和消息控制器23。
配置模块21,用于为界面中的所有Fragment配置消息控制器。
注册模块22,用于在所述消息控制器中注册所有的Fragment。
转发模块23,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
其中,所述配置模块21,还具体用于:
为每一个Fragment配置命令接口,并为该命令接口定义接口函数,所述接口函数中包括消息命令字和消息体参数。
参见图3,多Fragment之间的通信系统还包括维护模块24,所述维护模块24,用于对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。
其中,所述消息控制器23,还具体用于:
当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将消息发送给目的Fragment。
消息控制器23,还具体用于:
当接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息,以便使得接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。
参见图4,消息控制器23包括遍历单元231和调用单元232,其中,遍历单元231,用于通过循环的方式遍历对象集合中的所有Fragment对象。
调用单元232,用于每提取一个Fragment对象时,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息进行处理。
参见图5,为本发明一种电子设备,包括:处理器(processor)501、存储器(memory)502和总线503;其中,所述处理器501和存储器502通过所述总线503完成相互间的通信。
所述处理器501用于调用所述存储器502中的程序指令,以执行上述各方法实施例所提供的方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。本发明公开一种计算机程序产品,该计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,该计算机程序包括程序指令,当程序指令被计算机执行时,计算机能够执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
本发明还提供一种非暂态计算机可读存储介质,该非暂态计算机可读存 储介质存储计算机指令,该计算机指令使计算机执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
以上所描述的实施例仅仅是示意性的,其中作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分方法。
本发明提供了一种多Fragment之间的通信方法及系统,为界面中所有的Fragment配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的 Fragment,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。
最后,本申请的方法仅为较佳的实施方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
Claims (11)
- 一种多Fragment之间的通信方法,其特征在于,包括:S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment均处于平等关系;S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
- 如权利要求1所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。
- 如权利要求2所述的多Fragment之间的通信方法,其特征在于,所述步骤S2还包括:对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。
- 如权利要求3所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。
- 如权利要求4所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息中的消息体进行处理。
- 如权利要求5所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:消息控制器通过循环的方式遍历对象集合中的所有Fragment对象;每提取一个Fragment对象,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息中的消息体进行处理。
- 如权利要求4所述的多Fragment之间的通信方法,其特征在于,所述消息中还包括目的Fragment标识,所述步骤S2进一步包括:消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。
- 一种多Fragment之间的通信系统,其特征在于,所述配置模块,用于为界面中的所有Fragment配置消息控制器;注册模块,用于在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;转发模块,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。
- 一种电子设备,其特征在于,包括:至少一个处理器、至少一个存储器、通信接口和总线;其中,所述处理器、存储器、通信接口通过所述总线完成相互间的通信;所述通信接口用于该设备与玩具控制系统的通信设备之间的信息传输;所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如权利要求1-7任一项所述的方法。
- 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,所述计算机指令使所述计算机执行如权利要求1-7任一项所述的方法。
- 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行如权利要 求1-7任一项所述的方法。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710556420.1A CN107368311B (zh) | 2017-07-10 | 2017-07-10 | 一种多Fragment之间的通信方法及系统 |
| CN201710556420.1 | 2017-07-10 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2019010928A1 true WO2019010928A1 (zh) | 2019-01-17 |
Family
ID=60306093
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2017/120152 Ceased WO2019010928A1 (zh) | 2017-07-10 | 2017-12-29 | 一种多Fragment之间的通信方法及系统 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN107368311B (zh) |
| WO (1) | WO2019010928A1 (zh) |
Families Citing this family (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107368311B (zh) * | 2017-07-10 | 2021-07-23 | 武汉斗鱼网络科技有限公司 | 一种多Fragment之间的通信方法及系统 |
| CN109005448B (zh) * | 2018-06-28 | 2021-06-15 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN109086107B (zh) * | 2018-06-28 | 2021-06-15 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN108989872B (zh) * | 2018-07-10 | 2021-01-01 | 武汉斗鱼网络科技有限公司 | 一种安卓电视背景快速切换方法、框架、服务器及存储介质 |
| CN108924653B (zh) * | 2018-07-19 | 2021-01-01 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备和存储介质 |
| CN109089163B (zh) * | 2018-07-27 | 2021-05-28 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN109062650B (zh) * | 2018-08-01 | 2021-06-15 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN109144639B (zh) * | 2018-08-07 | 2021-09-07 | 武汉斗鱼网络科技有限公司 | 弹幕消息分发方法、装置、设备及存储介质 |
| CN110968313A (zh) * | 2018-09-30 | 2020-04-07 | 北京奇虎科技有限公司 | 一种fragment管理框架、方法及装置 |
| CN111309415B (zh) * | 2020-01-17 | 2024-01-02 | 北京有竹居网络技术有限公司 | 应用程序的用户界面ui信息处理方法、装置及电子设备 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP2615557A1 (en) * | 2010-09-06 | 2013-07-17 | Funai Electric Co., Ltd. | Multi-user communication system, method and device |
| CN105224310A (zh) * | 2015-09-06 | 2016-01-06 | 浪潮软件股份有限公司 | 一种基于android多fragment提升hybrid应用体验的方法 |
| CN105468344A (zh) * | 2014-08-26 | 2016-04-06 | 腾讯科技(深圳)有限公司 | 一种浮动层设置方法、装置及电子设备 |
| CN105955832A (zh) * | 2016-05-12 | 2016-09-21 | 武汉斗鱼网络科技有限公司 | 一种设备屏幕页面与子页面之间互相通信的方法及系统 |
| CN107368311A (zh) * | 2017-07-10 | 2017-11-21 | 武汉斗鱼网络科技有限公司 | 一种多Fragment之间的通信方法及系统 |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104184618B (zh) * | 2014-08-12 | 2017-11-07 | 烽火通信科技股份有限公司 | Android终端及其实现TR069网管代理的方法 |
-
2017
- 2017-07-10 CN CN201710556420.1A patent/CN107368311B/zh active Active
- 2017-12-29 WO PCT/CN2017/120152 patent/WO2019010928A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP2615557A1 (en) * | 2010-09-06 | 2013-07-17 | Funai Electric Co., Ltd. | Multi-user communication system, method and device |
| CN105468344A (zh) * | 2014-08-26 | 2016-04-06 | 腾讯科技(深圳)有限公司 | 一种浮动层设置方法、装置及电子设备 |
| CN105224310A (zh) * | 2015-09-06 | 2016-01-06 | 浪潮软件股份有限公司 | 一种基于android多fragment提升hybrid应用体验的方法 |
| CN105955832A (zh) * | 2016-05-12 | 2016-09-21 | 武汉斗鱼网络科技有限公司 | 一种设备屏幕页面与子页面之间互相通信的方法及系统 |
| CN107368311A (zh) * | 2017-07-10 | 2017-11-21 | 武汉斗鱼网络科技有限公司 | 一种多Fragment之间的通信方法及系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107368311A (zh) | 2017-11-21 |
| CN107368311B (zh) | 2021-07-23 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN107368311B (zh) | 一种多Fragment之间的通信方法及系统 | |
| ES2765415T3 (es) | Aparato, método y programa de procesamiento de datos basado en microservicios | |
| US20210126986A1 (en) | Distributed processing system and method for the provision of location based services | |
| US20190132276A1 (en) | Unified event processing for data/event exchanges with existing systems | |
| US8813093B2 (en) | Integration of disparate applications on a network | |
| Acar et al. | Designing an IoT cloud solution for aquaculture | |
| US20120016999A1 (en) | Context for Sharing Data Objects | |
| US10942792B2 (en) | Event driven subscription matching | |
| WO2020253465A1 (zh) | 一种文件交互处理方法、装置及系统 | |
| US11334334B2 (en) | Generating a software release based on controller metadata | |
| CN108780409B (zh) | 通用通知流水线 | |
| CN115225482A (zh) | 一种基于Kubernetes进行Pod容器网络配置的方法及装置 | |
| US20230123538A1 (en) | System and method for performing last-mile processing automation | |
| CA3041546A1 (en) | Apparatus and method for communicating data in a multi-tennant computer system | |
| CN109240684A (zh) | 一种页面业务逻辑实现方法及系统 | |
| WO2018223678A1 (zh) | 一种数据处理方法及处理装置 | |
| CN114385375A (zh) | 一种基于iframe可跨域、跨平台实时通讯的实现方案 | |
| CN116233217B (zh) | 基于路由的页面跳转方法、装置、电子设备及存储介质 | |
| CN103763325A (zh) | 构建ip安防产品开发环境的方法 | |
| US9729434B2 (en) | Processing requests for services in a service request at a receiving controller and processing controller in a switch | |
| CN106911739A (zh) | 一种信息分发方法及装置 | |
| JP7524480B2 (ja) | ウェブサービスと非ウェブサービスとの間でメッセージを通信するためのシステムおよび方法 | |
| US20130212601A1 (en) | Method and system for maintaining game functionality for a plurality of game instances running on a computer system | |
| WO2018120960A1 (zh) | 基于代理的业务处理方法、装置及网元设备 | |
| EP3316174B1 (en) | Channel-based mandatory access controls |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 17917689 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 17917689 Country of ref document: EP Kind code of ref document: A1 |
