WO2019010928A1 - Communication method and system among multiple fragments - Google Patents

Communication method and system among multiple fragments Download PDF

Info

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
Application number
PCT/CN2017/120152
Other languages
French (fr)
Chinese (zh)
Inventor
张磊
张文明
陈少杰
Original Assignee
武汉斗鱼网络科技有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2019010928A1 publication Critical patent/WO2019010928A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/44Arrangements for executing specific programs
    • G06F9/451Execution 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

A communication method and system among multiple Fragments. The method comprises: configuring a message controller for all Fragments in an interface, and registering all the Fragments in the message controller, wherein all the registered Fragments are under an equal relationship (S1); and on the basis of a command interface defined for each Fragment and an interface function of the command interface, forwarding the message of a source Fragment to a target Fragment by the message controller (S2). By the method, message managers are configured for all Fragments in the interface, communication among different Fragments is realized by the approach of forwarding messages by the message controller, so that chaos caused by direct communication among the plurality of Fragments is avoided; furthermore, when the plurality of Fragments have a nesting relationship, the problem in the prior art of complex communication due to the layer-by-layer issuing of messages can be avoided.

Description

一种多Fragment之间的通信方法及系统Communication method and system between multiple Fragment
交叉引用cross reference
本申请引用于2017年7月10日提交的专利名称为“一种多Fragment之间的通信方法及系统”的第201710556420.1号中国专利申请,其通过引用被全部并入本申请。The present application is hereby incorporated by reference in its entirety in its entirety in its entirety in its entirety in the the the the the the the the the the the the the the
技术领域Technical field
本发明涉及通信技术领域,更具体地,涉及一种多Fragment之间的通信方法及系统。The present invention relates to the field of communication technologies, and in particular, to a communication method and system between multiple Fragment.
背景技术Background technique
在Android开发过程中,通常会涉及到界面相关的编程,Fragment为整个界面中的碎片元素,可以理解为Fragment为界面中的一部分。In the Android development process, interface-related programming is usually involved. Fragment is a fragment element in the entire interface, which can be understood as Fragment as part of the interface.
一个界面可以装载一个或多个Fragment,比如,整个界面包含三个tab元素,每一个tab元素为界面中的一个页面,tab页面之间可以切换,一个tab页面的切换可以由一个Fragment来控制。在开发过程中,一个Fragment可以控制一个页面的业务逻辑,多个Fragment可以分离和独立各个页面的业务逻辑,方便后期维护。An interface can load one or more fragments. For example, 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. In the development process, 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.
多个Fragment之间需要进行通信,传统的方式是Fragment之间直接通信,这样如果Fragment的数量很多时,Fragment之间的通信会比较混乱,同时,若多个Fragment之间存在嵌套引用关系,则顶层的Fragment向最底层的Fragment发送消息时,需要通过各级的Fragment逐层进行转发,通信速度慢。Communication between multiple Fragments is required. The traditional way is to directly communicate between Fragment, so if the number of Fragment is large, the communication between Fragments will be confusing. At the same time, if there are nested reference relationships between multiple Fragments, When the top-level Fragment sends a message to the lowest-level Fragment, it needs to be forwarded layer by layer through the Fragment of each level, and the communication speed is slow.
发明内容Summary of the invention
本发明提供一种克服上述问题或者至少部分地解决上述问题的多Fragment之间的通信方法及系统。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.
根据本发明的第一个方面,提供一种多Fragment之间的通信方法,包括:According to a first aspect of the present invention, a communication method between multiple Fragments is provided, including:
S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;S1, 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;
S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,而不需通过一级一级的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; When there is a nested relationship between the Fragments, since all the Fragments registered in the message controller in this embodiment are in a peer relationship, when 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.
在上述技术方案的基础上,本发明还可以作如下改进。Based on the above technical solutions, the present invention can also be improved as follows.
进一步的,所述步骤S2进一步包括:Further, the step S2 further includes:
为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。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.
进一步的,所述步骤S2还包括:Further, the step S2 further includes:
对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。For all Fragments registered to the message controller, maintain a collection of objects in the message controller that hold all registered Fragment objects.
进一步的,所述步骤S2进一步包括:Further, the step S2 further includes:
当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。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.
进一步的,所述步骤S2进一步包括:Further, the step S2 further includes:
当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;When the message controller receives the message sent by the source fragment, the message is broadcast to the Fragment registered with the message controller;
接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。The Fragment that receives the message determines whether the message needs to be processed according to the message command word in the message.
进一步的,所述步骤S2进一步包括:Further, the step S2 further includes:
消息控制器通过循环的方式遍历对象集合中的所有Fragment对象;The message controller traverses all the Fragment objects in the object collection in a round-robin manner;
每提取一个Fragment对象,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息进行处理。Each time a Fragment object is extracted, 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. .
进一步的,所述消息中还包括目的Fragment标识,所述步骤S2进一步包括:Further, the message further includes a destination Fragment identifier, and the step S2 further includes:
消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。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.
根据本发明的第二个方面,还提供了一种多Fragment之间的通信系统,包括:According to a second aspect of the present invention, there is also provided a communication system between multiple Fragments, comprising:
配置模块,用于为界面中的所有Fragment配置消息控制器;a configuration module configured to configure a message controller for all the Fragments in the interface;
注册模块,用于在所述消息控制器中注册所有的Fragment;a registration module, configured to register all the Fragment in the message controller;
转发模块,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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.
根据本发明的第三个方面,提供了一种多Fragment之间的通信方法的设备,包括处理器(processor)、存储器(memory)和总线;According to a third aspect of the present invention, an apparatus for a communication method between multiple Fragments is provided, 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.
根据本发明的第四个方面,提供了一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行上述各实施方法。According to a fourth aspect of the present invention, there is provided a non-transitory computer readable storage medium storing computer instructions that cause the computer to perform the various implementation methods described above.
附图说明DRAWINGS
图1为本发明一个实施例的多Fragment之间的通信方法流程图;1 is a flow chart of a communication method between multiple Fragments according to an embodiment of the present invention;
图2为本发明另一个实施例的多Fragment之间的通信系统连接框图;2 is a block diagram showing a communication system connection between multiple Fragments according to another embodiment of the present invention;
图3为本发明又一个实施例的多Fragment之间的通信系统的整体连接框图;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;
图4为本发明再一个实施例的消息控制器内部连接框图;4 is a block diagram showing the internal connection of a message controller according to still another embodiment of the present invention;
图5为本发明一个实施例的电子设备连接框图。FIG. 5 is a block diagram of an electronic device connection according to an embodiment of the present invention.
具体实施方式Detailed ways
下面结合附图和实施例,对本发明的具体实施方式作进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。The specific embodiments of the present invention are further described in detail below with reference to the drawings and embodiments. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
参见图1,提供了本发明一个实施例的多Fragment之间的通信方法,包括:S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment;S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。Referring to FIG. 1, a communication method between multiple Fragment according to an embodiment of the present invention is provided, 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.
在Android的开发过程中,通常会涉及到界面相关的编程,在一个界面经常会有多个Fragment,其中,Fragment可以理解为碎片元素,即一个界面中可以包含多个碎片元素。一个Fragment可以管理一个页面的业务逻辑,多个Fragment可以将各个页面的业务逻辑进行分离和独立。各个Fragment之间需要通信,传统的方式是Fragment之间直接通信,即源Fragment直接向目的Fragment发送消息。采用该种通信的方式,如果Fragment的数量很多时,Fragment之间的通信会比较混乱;同时,若多个Fragment之间存在嵌套引用关系,则顶层的Fragment向最底层的Fragment发送消息时,需要逐层进行转发,通信速度慢。In the development process of Android, interface-related programming is usually involved. There are often multiple Fragments in an interface. 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. In this way of communication, if the number of Fragment is large, the communication between Fragment will be confusing; at the same time, if there is a nested reference relationship between multiple Fragments, when the top Fragment sends a message to the lowest Fragment, It needs to be forwarded layer by layer, and the communication speed is slow.
因此,本实施例为了解决上述的问题,为多个Fragment之间提供了一套简单的通信方法。在具体的实现过程中,为了实现多个Fragment之间的通信,设计多个Fragment之间进行通信的通信协议,后续的Fragment之间都遵循本协议来进行通信,具体设计多个Fragment之间的通信协议是,为界面中的每一个Fragment定义命令接口和接口函数。同时,为界面中的所有的Fragment配置消息控制器,其中,消息控制器用来对所有的Fragment 进行控制。在本实施例中,基于为每一个Fragment定义的命令接口和接口函数,消息控制器主要实现多个Fragment之间消息的转发。Therefore, in order to solve the above problem, the present embodiment provides a simple communication method between a plurality of Fragments. In the specific implementation process, in order to realize communication between multiple Fragment, 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. At the same time, a message controller is configured for all the Fragments in the interface, wherein the message controller is used to control all the Fragments. In this embodiment, based on the command interface and interface function defined for each Fragment, the message controller mainly implements forwarding of messages between multiple Fragments.
在本实施例中,一个Fragment在向另一个Fragment发送消息时,为描述方便,发送消息的Fragment称为源Fragment,接收消息的Fragment称为目的Fragment。源Fragment先将消息发送给消息控制器,由消息控制器将消息转发给目的Fragment。目的Fragment要接收消息控制器中的消息,需要向消息控制器中进行注册,只有在消息控制器中注册过的Fragment,才能接收到消息控制器转发的消息。另外,在源Fragment与消息控制器以及消息控制器与目的Fragment之间通信的过程中,均是基于上述通信协议实现通信的。In this embodiment, when a Fragment sends a message to another Fragment, for convenience of description, the Fragment that sends the message is called the source Fragment, and 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. In addition, in the process of communication between the source Fragment and the message controller and the message controller and the destination Fragment, communication is implemented based on the above communication protocol.
本实施例为界面中所有的Fragment配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。In this embodiment, 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 When there is a nested relationship, since all the Fragments registered in the message controller in this embodiment are in a peer relationship, when the source Fragment sends a message to the destination Fragment having a nested relationship, 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.
在上述实施例的基础上,本发明的一个实施例中,所述步骤S2进一步包括:为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。On the basis of the foregoing embodiment, in an embodiment of the present invention, 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.
在为多个Fragment之间设计通信协议的过程中,为每一个Fragment设计一套命令接口,为了能够兼容所有的消息,设计的通信协议可以分为两部分,第一部分为消息命令字,主要用来表示消息的类型,第二部分为消息体,也即消息的具体内容。设计的命令接口的程序代码如下:In the process of designing a communication protocol between multiple Fragments, a set of command interfaces is designed for each Fragment. 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:
Figure PCTCN2017120152-appb-000001
Figure PCTCN2017120152-appb-000001
其中interface表示该协议是一个接口协议,IMessage表示该接口协议的名称;onMessage表示该接口协议所包含的接口函数,它的返回值是void类型的,也就是说没有返回值。该接口函数包含有两个参数信息,其一是一个String(字符串)类型的command,command表示下发的消息命令字,另一个参数是Object类型的message,之所以设计成Object类型是为了能够通过该接口函数接收所有类型的消息。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.
通过观察,可以发现上述接口函数中的每一个参数都带有一个前缀@NoNullable,表明向接口函数中传递的参数不能为空(null),是为了确保参数的非空。By observing, it can be found that 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.
通过上述程序化的语言描述了通信接口设计,可以通过命令和消息的模式来进行任何消息的传递,Fragment为了能够接收消息,需要遵循上述设计的通信协议。上述程序化的展现即是Fragment需要继承IMessage接口,并且复写其中的onMessage方法。通过这样的处理后,fragment就是一个继承于IMessage接口的Fragment,也就具备了接收IMessage接口发送的消息的能力。The communication interface design is described by the above programmed language, and any message can be transmitted through the command and message mode. In order to receive the message, 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.
另外,Fragment要接收消息控制器转发的消息,必须向消息控制器进行注册,只有向消息控制器进行注册过的Fragment才能够接收消息控制器分发的消息。其中,具体的注册过程为:Fragment是一个类,每个类都有构造函数,在Fragment的构造函数中实施注册,就能够保证Fragment被实例化时,主动被注册到消息控制器中。In addition, 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.
在Fragment的构造函数中调用消息控制器中的消息注册器register(this.fragment),将该Fragment对象注册到消息控制器中。其中,注册到消息控制器中的所有的Fragment都处于对等的关系,即所有的Fragment属于平等的关系,现有中的多个Fragment会存在嵌套关系,即多个Fragment是具有层级关系的,而在本实施例中,通过向消息控制器进行注册来消息这种层级关系,在消息控制器中注册过的所有的Fragment都处于对等的关系。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. Among them, 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. In the present embodiment, 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.
在上述各个实施例的基础上,本发明的另一个实施例中,所述步骤S2还包括:对于注册到消息控制器的所有Fragment,在消息控制器内维护一个 用来存放所有注册的Fragment对象的对象集合。Based on the foregoing various embodiments, in another embodiment of the present invention, 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.
当界面中所有的Fragment都注册到消息控制器中后,在消息控制器中维护一个对象集合,该对象集合主要用来存放所有注册到消息控制器中的Fragment,以便后续消息控制器能够像Fragment分发消息。After all the Fragments in the interface are registered in the message controller, a set of objects is maintained in the message controller, and the object set is mainly used to store all the Fragment registered in the message controller, so that the subsequent message controller can be like Fragment. Distribute the message.
在上述各个实施例的基础上,本发明的另一个实施例中,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。On the basis of the foregoing various embodiments, in another embodiment of the present invention, 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.
在消息控制器接收到源Fragment发送的消息,向目的Fragment转发的过程中,消息控制器可以采用两种方式进行转发,一种是以广播的方式向目的Fragment转发消息,另一种是通过点对点的方式向目的Fragment转发消息,实现多种方式的灵活分发。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.
在上述各实施例的基础上,本发明的一个实施例中,所述步骤S2进一步包括:当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。In an embodiment of the present invention, in step S2, the 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.
上述已经说明,在消息控制器向目的Fragment转发消息时,可以采用广播的方式或者点对点的方式。当消息控制器以广播的方式发送消息时,消息控制器接收到一个Fragment的消息时,向在消息控制器中注册过的Fragment广播该消息,其中,消息中包括消息命令字和消息体。接收到消息的Fragment根据消息中的消息命令字,来确定该消息是否为自身所需的消息,若是需要的消息,则获取该消息并进行处理。As described above, when the message controller forwards the message to the destination Fragment, it may be broadcast or peer-to-peer. When 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.
其中,消息控制器向在消息控制器中注册过的Fragment广播消息的具体过程为:消息控制器通过for循环的方式遍历对象集合中的所有Fragment对象,并从对象集合中逐个提取Fragment。每提取一个Fragment对象,则调用该Fragment对象中的接口函数onMessage,并将从发送消息的Fragment接收的消息传递到该Fragment对象的接口函数onMessage中,由该接口函数onMessage根据消息中的消息命令字确定是否需要对该消息进行处理,这样就通过消息控制器的转发完成了一个Fragment向另一个Fragment发送消 息的过程。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.
在本发明的另一个实施例中,所述步骤S2进一步包括:消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。In another embodiment of the present invention, 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.
上述实施例消息控制器是通过广播的方式来转发消息的,而本实施例中消息控制器是通过点对点的方式来转发消息的。具体为,当消息控制器接收到源Fragment发送的消息时,其中,消息中包括需要发送消息的目的Fragment标识。消息控制器根据消息中的目的Fragment标识,将消息直接转发给目的Fragment。In the foregoing embodiment, 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.
通过上述两种方式,可以看出本方案中消息的传递是通过消息控制器来进行转发的,并不是传统的Fragment之间直接通信的方式,通过消息控制器对消息进行转发的设计方式,由于在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的Fragment,使得消息的收发与Fragment所在的层级无关联性,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。Through the above two methods, it can be seen that 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. When 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.
参见图2,提供了本发明另一个实施例的多Fragment之间的通信系统,包括配置模块21、注册模块22和消息控制器23。Referring to FIG. 2, a communication system between multiple Fragments of another embodiment of the present invention is provided, including a configuration module 21, a registration module 22, and a message controller 23.
配置模块21,用于为界面中的所有Fragment配置消息控制器。The configuration module 21 is configured to configure a message controller for all the fragments in the interface.
注册模块22,用于在所述消息控制器中注册所有的Fragment。The registration module 22 is configured to register all the Fragments in the message controller.
转发模块23,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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.
其中,所述配置模块21,还具体用于:The configuration module 21 is further configured to:
为每一个Fragment配置命令接口,并为该命令接口定义接口函数,所述接口函数中包括消息命令字和消息体参数。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.
参见图3,多Fragment之间的通信系统还包括维护模块24,所述维护模块24,用于对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。Referring to FIG. 3, 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.
其中,所述消息控制器23,还具体用于:The message controller 23 is further specifically configured to:
当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将消息发送给目的Fragment。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.
消息控制器23,还具体用于:The message controller 23 is also specifically used to:
当接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息,以便使得接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息进行处理。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. .
参见图4,消息控制器23包括遍历单元231和调用单元232,其中,遍历单元231,用于通过循环的方式遍历对象集合中的所有Fragment对象。Referring to FIG. 4, 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.
调用单元232,用于每提取一个Fragment对象时,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息进行处理。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.
参见图5,为本发明一种电子设备,包括:处理器(processor)501、存储器(memory)502和总线503;其中,所述处理器501和存储器502通过所述总线503完成相互间的通信。Referring to FIG. 5, an electronic device according to the present invention 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. .
所述处理器501用于调用所述存储器502中的程序指令,以执行上述各方法实施例所提供的方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。本发明公开一种计算机程序产品,该计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,该计算机程序包括程序指令,当程序指令被计算机执行时,计算机能够执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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.
本发明还提供一种非暂态计算机可读存储介质,该非暂态计算机可读存 储介质存储计算机指令,该计算机指令使计算机执行上述对应实施例所提供的智能过滤的控件布局方法,例如包括:为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的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.
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。A person skilled in the art can understand that all or part of the steps of implementing the above method embodiments may be completed by using hardware related to the program instructions. 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 embodiments described above are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, ie may be located in one place. Or it can be distributed to multiple network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. Those of ordinary skill in the art can understand and implement without deliberate labor.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the various embodiments can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware. Based on such understanding, the above-described technical solutions may be embodied in the form of software products in essence or in the form of software products, which may be stored in a computer readable storage medium such as ROM/RAM, magnetic Discs, optical discs, etc., include instructions for causing a computer device (which may be a personal computer, server, or network device, etc.) to perform various embodiments of the various embodiments or embodiments.
本发明提供了一种多Fragment之间的通信方法及系统,为界面中所有的Fragment配置消息管理器,由消息控制器进行转发的方式实现一个Fragment向另一个Fragment发送消息,避免多个Fragment之间直接通信的混乱;以及当多个Fragment之间存在嵌套关系时,由于本实施例在消息控制器中注册的所有的Fragment是处于对等的关系,在源Fragment向具有嵌套关系的目的Fragment发送消息时,直接由消息控制器转发给目的 Fragment,而不需通过一级一级的Fragment进行传递,避免现有的需要一层一层逐级下发消息带来的通信复杂的问题。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. When 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.
最后,本申请的方法仅为较佳的实施方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。Finally, the method of the present application is only a preferred embodiment and is not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Claims (11)

  1. 一种多Fragment之间的通信方法,其特征在于,包括:A communication method between multiple Fragments, comprising:
    S1,为界面中的所有Fragment碎片配置消息控制器,并且在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment均处于平等关系;S1, 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;
    S2,基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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.
  2. 如权利要求1所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:The method of communicating between multiple Fragments according to claim 1, wherein the step S2 further comprises:
    为每一个Fragment定义命令接口,并为该命令接口定义接口函数,所述接口函数中至少包括消息命令字和消息体参数。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.
  3. 如权利要求2所述的多Fragment之间的通信方法,其特征在于,所述步骤S2还包括:The method of communicating between multiple Fragments according to claim 2, wherein the step S2 further comprises:
    对于注册到消息控制器的所有Fragment,在消息控制器内维护一个用来存放所有注册的Fragment对象的对象集合。For all Fragments registered to the message controller, maintain a collection of objects in the message controller that hold all registered Fragment objects.
  4. 如权利要求3所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:The method of communicating between multiple Fragments according to claim 3, wherein the step S2 further comprises:
    当消息控制器接收到源Fragment发送的消息时,以广播的方式或者点对点的方式将所述消息发送给目的Fragment。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.
  5. 如权利要求4所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:The method of communicating between multiple Fragments according to claim 4, wherein the step S2 further comprises:
    当消息控制器接收到源Fragment发送的消息时,向注册过消息控制器的Fragment广播所述消息;When the message controller receives the message sent by the source fragment, the message is broadcast to the Fragment registered with the message controller;
    接收到所述消息的Fragment根据所述消息中的消息命令字,确定是否需要对该消息中的消息体进行处理。The Fragment receiving the message determines whether the message body in the message needs to be processed according to the message command word in the message.
  6. 如权利要求5所述的多Fragment之间的通信方法,其特征在于,所述步骤S2进一步包括:The method of communicating between multiple Fragments according to claim 5, wherein the step S2 further comprises:
    消息控制器通过循环的方式遍历对象集合中的所有Fragment对象;The message controller traverses all the Fragment objects in the object collection in a round-robin manner;
    每提取一个Fragment对象,调用该Fragment对象中的接口函数,将所述消息传递到该Fragment对象的接口函数中,由该接口函数根据所述消息中的消息命令字确定是否需要对该消息中的消息体进行处理。Each time a Fragment object is extracted, 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 in the message according to the message command word in the message. The message body is processed.
  7. 如权利要求4所述的多Fragment之间的通信方法,其特征在于,所述消息中还包括目的Fragment标识,所述步骤S2进一步包括:The communication method of the multi-Fragment according to claim 4, wherein the message further includes a destination Fragment identifier, and the step S2 further comprises:
    消息控制器接收到源Fragment发送的消息,根据消息中的目的Fragment标识,将所述消息转发给目的Fragment。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.
  8. 一种多Fragment之间的通信系统,其特征在于,所述A communication system between multiple Fragments, characterized in that
    配置模块,用于为界面中的所有Fragment配置消息控制器;a configuration module configured to configure a message controller for all the Fragments in the interface;
    注册模块,用于在所述消息控制器中注册所有的Fragment,其中,所有注册的Fragment处于平等关系;a registration module for registering all Fragments in the message controller, wherein all registered Fragments are in an equal relationship;
    转发模块,用于基于为每一个Fragment定义的命令接口及其接口函数,由消息控制器将源Fragment的消息转发至目的Fragment。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.
  9. 一种电子设备,其特征在于,包括:An electronic device, comprising:
    至少一个处理器、至少一个存储器、通信接口和总线;At least one processor, at least one memory, a communication interface, and a bus;
    其中,所述处理器、存储器、通信接口通过所述总线完成相互间的通信;Wherein the processor, the memory, and the communication interface complete communication with each other through the bus;
    所述通信接口用于该设备与玩具控制系统的通信设备之间的信息传输;The communication interface is used for information transmission between the device and a communication device of the toy control system;
    所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如权利要求1-7任一项所述的方法。The memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the method of any of claims 1-7.
  10. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,所述计算机指令使所述计算机执行如权利要求1-7任一项所述的方法。A computer program product, comprising: a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions, when the program instructions are executed by a computer, The computer instructions cause the computer to perform the method of any of claims 1-7.
  11. 一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行如权利要 求1-7任一项所述的方法。A non-transitory computer readable storage medium, wherein the non-transitory computer readable storage medium stores computer instructions, the computer instructions causing the computer to perform the method of any of claims 1-7 method.
PCT/CN2017/120152 2017-07-10 2017-12-29 Communication method and system among multiple fragments WO2019010928A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710556420.1A CN107368311B (en) 2017-07-10 2017-07-10 Method and system for communication among multiple fragments
CN201710556420.1 2017-07-10

Publications (1)

Publication Number Publication Date
WO2019010928A1 true WO2019010928A1 (en) 2019-01-17

Family

ID=60306093

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/120152 WO2019010928A1 (en) 2017-07-10 2017-12-29 Communication method and system among multiple fragments

Country Status (2)

Country Link
CN (1) CN107368311B (en)
WO (1) WO2019010928A1 (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107368311B (en) * 2017-07-10 2021-07-23 武汉斗鱼网络科技有限公司 Method and system for communication among multiple fragments
CN109005448B (en) * 2018-06-28 2021-06-15 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN109086107B (en) * 2018-06-28 2021-06-15 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN108989872B (en) * 2018-07-10 2021-01-01 武汉斗鱼网络科技有限公司 Android television background fast switching method, framework, server and storage medium
CN108924653B (en) * 2018-07-19 2021-01-01 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN109089163B (en) * 2018-07-27 2021-05-28 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN109062650B (en) * 2018-08-01 2021-06-15 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN109144639B (en) * 2018-08-07 2021-09-07 武汉斗鱼网络科技有限公司 Bullet screen message distribution method, device, equipment and storage medium
CN110968313A (en) * 2018-09-30 2020-04-07 北京奇虎科技有限公司 Fragment management framework, method and device
CN111309415B (en) * 2020-01-17 2024-01-02 北京有竹居网络技术有限公司 User Interface (UI) information processing method and device of application program and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
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 (en) * 2015-09-06 2016-01-06 浪潮软件股份有限公司 A kind of method promoting HYBRID application experience based on the many FRAGMENT of ANDROID
CN105468344A (en) * 2014-08-26 2016-04-06 腾讯科技(深圳)有限公司 Floating layer setting method and device, and electronic equipment
CN105955832A (en) * 2016-05-12 2016-09-21 武汉斗鱼网络科技有限公司 Method and system for intercommunication between activity and fragments in device screen
CN107368311A (en) * 2017-07-10 2017-11-21 武汉斗鱼网络科技有限公司 Communication means and system between a kind of more Fragment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104184618B (en) * 2014-08-12 2017-11-07 烽火通信科技股份有限公司 Android terminal and its method for realizing TR069 network management agents

Patent Citations (5)

* Cited by examiner, † Cited by third party
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 (en) * 2014-08-26 2016-04-06 腾讯科技(深圳)有限公司 Floating layer setting method and device, and electronic equipment
CN105224310A (en) * 2015-09-06 2016-01-06 浪潮软件股份有限公司 A kind of method promoting HYBRID application experience based on the many FRAGMENT of ANDROID
CN105955832A (en) * 2016-05-12 2016-09-21 武汉斗鱼网络科技有限公司 Method and system for intercommunication between activity and fragments in device screen
CN107368311A (en) * 2017-07-10 2017-11-21 武汉斗鱼网络科技有限公司 Communication means and system between a kind of more Fragment

Also Published As

Publication number Publication date
CN107368311A (en) 2017-11-21
CN107368311B (en) 2021-07-23

Similar Documents

Publication Publication Date Title
WO2019010928A1 (en) Communication method and system among multiple fragments
CN106790660B (en) A kind of dispositions method and device for realizing distributed memory system
US10776107B2 (en) Microservice-based data processing apparatus, method, and program
EP2840813B1 (en) Service method and system using instance interface of virtualization object in internet of things environment
CN105354076B (en) Application deployment method and device
US8572236B2 (en) Distributing services in graph-based computations
CN104461239B (en) A kind of information interacting method and device
CN105765578B (en) Parallel access of data in a distributed file system
US8813093B2 (en) Integration of disparate applications on a network
US20210126986A1 (en) Distributed processing system and method for the provision of location based services
US20090157872A1 (en) Model-based composite application platform
US10938868B2 (en) Application service integration
US20120016999A1 (en) Context for Sharing Data Objects
CN102185900A (en) Application service platform system and method for developing application services
US20090165021A1 (en) Model-Based Composite Application Platform
JP6624619B2 (en) Resource subscription method, resource subscription device, and resource subscription system
US20140250234A1 (en) Aggregation of sensor appliances using device registers and wiring brokers
CN107426599B (en) Floating layer management method and system
US11595299B2 (en) System and method of suppressing inbound payload to an integration flow of an orchestration based application integration
CN105786460A (en) Software development method and device based on service composition
WO2017066804A1 (en) Event driven subscription matching
CN108780409B (en) Universal notification pipeline
CN115480939A (en) Data sharing method, device and system based on message queue
CN109240684A (en) A kind of page service logic realization method and system
WO2018223678A1 (en) Data processing method and processing device

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