WO2023093675A1 - 一种双向通信方法、装置、设备及介质 - Google Patents

一种双向通信方法、装置、设备及介质 Download PDF

Info

Publication number
WO2023093675A1
WO2023093675A1 PCT/CN2022/133223 CN2022133223W WO2023093675A1 WO 2023093675 A1 WO2023093675 A1 WO 2023093675A1 CN 2022133223 W CN2022133223 W CN 2022133223W WO 2023093675 A1 WO2023093675 A1 WO 2023093675A1
Authority
WO
WIPO (PCT)
Prior art keywords
way communication
periodic table
present disclosure
communicate
identifier corresponding
Prior art date
Application number
PCT/CN2022/133223
Other languages
English (en)
French (fr)
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 WO2023093675A1 publication Critical patent/WO2023093675A1/zh

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

Definitions

  • the present disclosure relates to the field of computer technology, and in particular to a two-way communication method, device, equipment and medium.
  • Android is a free and open source operating system based on the Linux kernel. Primarily used on mobile devices such as smartphones and tablets.
  • Start Activity For Result is a cross-page communication method natively supported by the Android system.
  • Communication between open Activities does not support real-time communication.
  • ViewModel supports two-way real-time communication between components in an Activity, but does not support component communication between multiple activities.
  • EventBus supports real-time communication of components between multiple activities, but requires developers to code to ensure unsubscribing after the end of the activity life cycle, which is cumbersome to implement and highly coupled in code writing.
  • the present disclosure provides a two-way communication method, device, equipment and medium, which are used to detect information of a sending and receiving party in real time, thereby improving code compilation efficiency.
  • the embodiment of the present disclosure provides a two-way communication method, including: after determining that the first process and the second process will communicate, adding the identification corresponding to the first process and the identification corresponding to the second process in the periodic table; A two-way communication process, so that the first process communicates with the second process; and when it is determined that any process stops communicating, delete the identifier corresponding to any process in the periodic table.
  • the method further includes: after determining that the third process will communicate with the target process corresponding to any identifier in the periodic table, adding the third process to the periodic table the corresponding identification; and based on the two-way communication process, the third process communicates with the target process.
  • the method further includes: when there is no identifier corresponding to the process in the periodic table, stopping the two-way communication process.
  • the method after stopping the two-way communication process, the method further includes: deleting the two-way communication process and the periodic table.
  • the two-way communication process is generated in a shared area.
  • the embodiment of the present disclosure provides a two-way communication device, including: an adding unit, configured to add the identification corresponding to the first process and the second process to the periodic table after determining that the first process will communicate with the second process A corresponding identification; a communication unit, configured to enable the first process to communicate with the second process based on a two-way communication process; and a deletion unit, configured to delete any process corresponding to any process in the periodic table when it is determined that any process stops communicating. logo.
  • the adding unit is further configured to: after determining that the third process will communicate with the target process corresponding to any identifier in the periodic table, add the third process to the periodic table The identifications corresponding to the three processes; and the communication unit is further configured to: enable the third process to communicate with the target process based on the two-way communication process.
  • the communication unit is further configured to: stop the two-way communication process when there is no identification corresponding to the process in the periodic table.
  • the deleting unit is further configured to: delete the two-way communication process and the periodic table.
  • the two-way communication process is generated in a shared area.
  • an embodiment of the present disclosure provides a two-way communication device, including: a memory; a processor; and a computer program; wherein the computer program is stored in the memory and configured to be executed by the processor to implement the first aspect method.
  • an embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method in the first aspect.
  • an embodiment of the present disclosure further provides a computer program product, where the computer program product includes a computer program or an instruction, and when the computer program or instruction is executed by a processor, implements the above two-way communication method.
  • an embodiment of the present disclosure further provides a computer program, where the computer program includes instructions, and the instructions implement the above two-way communication method when executed by a processor.
  • FIG. 1 is a schematic diagram of the MVVM method provided by the background technology of the present disclosure
  • FIG. 2 is a schematic flowchart of a two-way communication method provided by an embodiment of the present disclosure
  • FIG. 3 is a schematic flowchart of a two-way communication method provided by an embodiment of the present disclosure
  • FIG. 4 is a schematic flowchart of another two-way communication method provided by an embodiment of the present disclosure.
  • FIG. 5 is a schematic diagram of a code structure provided by an embodiment of the present disclosure.
  • FIG. 6 is a schematic diagram of a calling process method provided by an embodiment of the present disclosure.
  • FIG. 7 is a schematic diagram of an MVVM method provided by an embodiment of the present disclosure.
  • FIG. 8 is a schematic structural diagram of a two-way communication device provided by an embodiment of the present disclosure.
  • FIG. 9 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • Android is a free and open source operating system based on the Linux kernel, mainly used in mobile devices.
  • EventBus An Android event publishing/subscribing lightweight framework, which can replace Android's traditional Intent, Handler, Broadcast or interface functions, and transfer data and execute methods between Fragment, Activity, and Service threads.
  • ViewModel Model-View-ViewModel, MVVM. It is essentially an improved version of MVC. MVVM is to abstract the state and behavior of the View in it.
  • the origin of the MVVM framework is a new type of architecture framework developed and evolved from the application of the combination of MVP (Model-View-Presenter) mode and WPF. It is based on the original MVP framework and incorporates the new features of WPF to cope with the increasingly complex needs of customers.
  • the cross-page communication method natively supported by the Android system has the advantage of being simple and easy to use, but it does not support real-time communication.
  • Android is a free and open source operating system based on the Linux kernel. Mainly used in mobile devices, such as smartphones and tablets, there are many communication methods between components in Android application development, such as Start Activity For Result, ViewModel and EventBus, etc. Start Activity For Result is a cross-page communication method natively supported by the Android system , is easy to use, but it can only communicate between two adjacent open Activities, and does not support real-time communication. As shown in Figure 1, ViewModel supports two-way real-time communication between components in an Activity, but does not support component communication between multiple activities. EventBus supports real-time communication of components between multiple activities, but requires developers to code to ensure unsubscribing after the end of the activity life cycle, which is cumbersome to implement and highly coupled in code writing.
  • the two-way communication solution provided by the embodiments of the present disclosure selects the ViewModel under Androidx, whose original capability supports communication between components.
  • the ViewModel under Androidx For multi-component real-time communication, we use the ViewModel under Androidx. Its original ability supports communication between components.
  • the ViewModel is generally stored in the ViewModelStore, and the ViewModelStore is stored in the Activity or Fragment, its life cycle and the Activity or Fragment stored in it unanimous.
  • an embodiment of the present disclosure provides a two-way communication method, including the following steps.
  • the identifications corresponding to the first process and the second process are respectively added in the periodic table.
  • the process communicates add the identification of the process in the periodic table.
  • the second process and the third process can communicate directly or indirectly via the first process. It is also possible to prevent communication between the second process and the third process, which is not limited in this embodiment of the present disclosure.
  • the two-way communication method when it is determined that the first process communicates with the second process, respectively add the identifiers corresponding to the first process and the second process in the periodic table, and then make the first process communicate with the second process communication, and when any process ceases to be used, its corresponding identifier is deleted from the periodic table. Real-time communication between processes is realized, communication efficiency is improved, and system resources are saved.
  • the identifier corresponding to the third process is added to the periodic table, thereby realizing real-time communication among multiple processes and improving communication efficiency.
  • the two-way communication process is generated in the shared area, and is not affected by the life cycle of the process, thereby improving communication efficiency.
  • FIG. 3 and FIG. 4 as examples.
  • FIG. 3 it is a two-way communication method provided by an embodiment of the present disclosure, and the method includes the following steps.
  • the process can use the viewmodel to communicate, and based on the periodic table, it is guaranteed that after the process stops communicating and the viewmodel is closed, the retained process information is thrown away, and the new viewmodel is enabled when other processes communicate. It is possible to communicate directly, but this solution requires opening and closing the viewmodel multiple times, which is not conducive to specific implementation. Therefore, as shown in FIG. 4 , the embodiment of the present disclosure provides another two-way communication method, and the specific steps are as follows.
  • the UML diagram of the code structure provided by the embodiment of the present disclosure firstly defines the ClearUselessViewModelObserver and implements the LifecycleEventObserver interface. Pass the lifecycle object and map object to ClearUselessViewModelObserver, and then implement the onStateChanged method of the LifecycleEventObserver interface. This method removes the lifecycle in the previous step from the value corresponding to the map when the parameter LifecycleEvent is Event.DESTROYED.
  • the first process and the second process are allowed to perform viewmodel communication.
  • the process name of the process is deleted from the lifecycle.
  • the viewmodel is removed from the store.
  • FIG. 7 it is a schematic diagram of using a shared space for viewmodel communication.
  • a new ViewModelStore is added to the SharedViewModel. Its life cycle no longer follows a certain Activity and Fragment, but is consistent with the Android Application life cycle, that is, the same instance can be obtained through this ViewModelStore during the running of the App. ViewModel.
  • a reference list is maintained in the SharedViewModel, which records the ViewModel instance and the Lifecycle instance that uses the ViewModel instance.
  • the Lifecycle instance will be recorded in the list.
  • the life cycle of the recorded Lifecycle instance ends to the DESTROYED state, the Lifecycle instance will be removed from the list, and the ViewModel will be released when all Lifecycle instances are removed from the list.
  • FIG. 8 is a two-way communication device provided by an embodiment of the present disclosure, including: an adding unit 801, configured to add the identifier corresponding to the first process and the second process to the periodic table after determining that the first process and the second process will communicate. The identification corresponding to the process; the communication unit 802, configured to enable the first process to communicate with the second process based on the two-way communication process; and the deletion unit 803, configured to delete any process in the periodic table when it is determined that any process stops communicating corresponding ID.
  • the adding unit 801 is further configured to: after determining that the third process will communicate with the target process corresponding to any identifier in the periodic table, add The identifier corresponding to the third process; and the communication unit 802 is further configured to: enable the third process to communicate with the target process based on the two-way communication process.
  • the communication unit 802 is further configured to: stop the two-way communication process when there is no identifier corresponding to the process in the periodic table.
  • the deleting unit 803 is further configured to: delete the two-way communication process and the periodic table.
  • the two-way communication process is generated in a shared area.
  • FIG. 9 shows a schematic diagram of a hardware structure of an electronic device provided by an embodiment of the present disclosure.
  • the electronic device may include a processor 901 and a memory 902 storing computer program instructions.
  • the above-mentioned processor 901 may include a central processing unit (CPU), or an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present disclosure.
  • CPU central processing unit
  • ASIC Application Specific Integrated Circuit
  • Memory 902 may include mass storage for data or instructions.
  • memory 902 may include a hard disk drive (Hard Disk Drive, HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (Universal Serial Bus, USB) drive or two or more Combinations of multiple of the above.
  • Storage 902 may include removable or non-removable (or fixed) media, where appropriate.
  • Memory 902 may be internal or external to the data processing arrangement, where appropriate.
  • memory 902 is a non-volatile solid-state memory.
  • memory 902 includes read-only memory (ROM).
  • the ROM may be mask programmed ROM, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), electrically rewritable ROM (EAROM), or flash memory or A combination of two or more of the above.
  • the processor 901 reads and executes the computer program instructions stored in the memory 902 to implement any method for determining recommended information in the above-mentioned embodiments.
  • the electronic device may further include a communication interface 903 and a bus 910 .
  • a processor 901 a memory 902 , and a communication interface 903 are connected through a bus 910 to complete mutual communication.
  • the communication interface 903 is mainly used to implement communication between modules, devices, units and/or devices in the embodiments of the present disclosure.
  • Bus 910 includes hardware, software, or both, and couples the components of the electronic device to each other.
  • the bus may include Accelerated Graphics Port (AGP) or other graphics bus, Enhanced Industry Standard Architecture (EISA) bus, Front Side Bus (FSB), HyperTransport (HT) interconnect, Industry Standard Architecture (ISA) Bus, Infiniband Interconnect, Low Pin Count (LPC) Bus, Memory Bus, Micro Channel Architecture (MCA) Bus, Peripheral Component Interconnect (PCI) Bus, PCI-Express (PCI-X) Bus, Serial Advanced Technology Attachment (SATA) bus, Video Electronics Standards Association Local (VLB) bus or other suitable bus or a combination of two or more of these.
  • Bus 910 may comprise one or more buses, where appropriate. Although embodiments of the present disclosure describe and illustrate a particular bus, this disclosure contemplates any suitable bus or interconnect.
  • the electronic device may execute the two-way communication method in the embodiments of the present disclosure based on the received service request sent by the smart device, so as to implement the two-way communication method and device described in conjunction with FIGS. 1-8 .
  • embodiments of the present disclosure may provide a computer-readable storage medium for implementation.
  • Computer program instructions are stored on the computer-readable storage medium; when the computer program instructions are executed by a processor, any two-way communication method in the above-mentioned embodiments is implemented.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

本公开涉及一种双向通信方法、装置、设备及介质,用以实现进程之间的实时通信,提高通信效率,节省***资源。该方法包括:确定第一进程与第二进程将进行通信后,在周期表中加入所述第一进程对应的标识和所述第二进程对应的标识;基于双向通信进程,使得所述第一进程与所述第二进程进行通信;确定任一进程停止双向通信时,在所述周期表中删除所述任一进程对应的标识。

Description

一种双向通信方法、装置、设备及介质
相关申请的交叉引用
本申请要求于2021年11月25日递交、申请号为202111413623.8、名称为“一种双向通信方法、装置、设备及介质”的中国专利申请的优先权,其全部内容通过引用并入本文。
技术领域
本公开涉及计算机技术领域,尤其涉及一种双向通信方法、装置、设备及介质。
背景技术
安卓(Android)是一种基于Linux内核的自由及开放源代码的操作***。主要使用于移动设备,如智能手机和平板电脑。
Android应用开发中有很多组件间的通信方式,诸如Start Activity For Result,ViewModel和EventBus等,Start Activity For Result是Android***原生支持的跨页面通信方式,简单易用,但只能在相邻的两个打开的Activity间通信,不支持实时通信。ViewModel支持在一个Activity中的组件双向的实时通信,但是不支持多个活动(Activity)之间的组件通信。EventBus支持在多个Activity之间的组件的实时通信,但需要开发人员代码保证Activity生命周期结束后取消订阅,实施繁琐,且代码编写耦合程度高。
因此,亟需提供一种简易的跨页面实时通信,用以克服以上现有的组件的问题。
发明内容
本公开提供了一种双向通信方法、装置、设备及介质,用以实时检测收发方信息,进而提升代码编译效率。
第一方面,本公开实施例提供一种双向通信方法,包括:确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识;基于双向通信进程,使得第一进程与第二进程进行通信;以及确定任一进程停止通信时,在周期表中删除任一进程对应的的标识。
在一种可能的实施方式中,本公开实施例提供的方法中,方法还包括:确定第三进程与周期表中任一标识对应的目标进程将进行通信后,在周期表中加入第三进程对应的标识;以及基于双向通信进程,使得第三进程与目标进程进行通信。
在一种可能的实施方式中,本公开实施例提供的方法中,方法还包括:在周期表中没有进程对应的标识时,停止双向通信进程。
在一种可能的实施方式中,本公开实施例提供的方法中,在停止双向通信进程之后,方法还包括:删除双向通信进程和周期表。
在一种可能的实施方式中,本公开实施例提供的方法中,双向通信进程是在共享区域内生成的。
第二方面,本公开实施例提供一种双向通信装置,包括:添加单元,用于确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识;通信单元,用于基于双向通信进程,使得第一进程与第二进程进行通信;以及删除单元,用于确定任一进程停止通信时,在周期表中删除任一进程对应的的标识。
在一种可能的实施方式中,本公开实施例提供的装置中,添加单元还用于:确定第三进程与周期表中任一标识对应的目标进程将进行通信后,在周期表中加入第三进程对应的标识;以及通信单元还用于:基于双向通信进程,使得第三进程与目标进程进行通信。
在一种可能的实施方式中,本公开实施例提供的装置中,通信单元还用于:在周期表中没有进程对应的标识时,停止双向通信进程。
在一种可能的实施方式中,本公开实施例提供的装置中,删除单元还用于:删除双向通信进程和周期表。
在一种可能的实施方式中,本公开实施例提供的装置中,双向通信进程是在共享区域内生成的。
第三方面,本公开实施例提供一种双向通信设备,包括:存储器;处理器;以及计算机程序;其中,计算机程序存储在存储器中,并被配置为由处理器执行以实现如第一方面的方法。
第四方面,本公开实施例提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行以实现第一方面的方法。
第五方面,本公开实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序或指令,该计算机程序或指令被处理器执行时实现如上的双向通信方法。
第六方面,本公开实施例还提供了一种计算机程序,该计算机程序包括指令,所述指令当由处理器执行时实现如上的双向通信方法。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。
为了更清楚地说明本公开实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,对于本领域普通技术人员而言,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本公开背景技术提供的MVVM方法示意图;
图2为本公开实施例提供的一种双向通信方法的流程示意图;
图3为本公开实施例提供的一种双向通信方法流程示意图;
图4为本公开实施例提供的另一双向通信方法流程示意图;
图5为本公开实施例提供的代码结构示意图;
图6为本公开实施例提供的调用过程方法示意图;
图7为本公开实施例提供的MVVM方法示意图;
图8为本公开实施例提供的一种双向通信装置的结构示意图;以及
图9为本公开实施例提供的电子设备的结构示意图。
具体实施方式
为了能够更清楚地理解本公开的上述目的、特征和优点,下面将对本公开的方案进行进一步描述。需要说明的是,在不冲突的情况下,本公开的实施例及实施例中的特征可以相互组合。
在下面的描述中阐述了很多具体细节以便于充分理解本公开,但本公开还可以采用其他不同于在此描述的方式来实施;显然,说明书中的实施例只是本公开的一部分实施例,而不是全部的实施例。
下面对文中出现的一些词语进行解释。
本公开实施例中术语“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。字符“/”一般表示前后关联对象是一种“或”的关系。
Android:安卓,是一种基于Linux内核的自由及开放源代码的操作***,主要使用于移动设备。
EventBus:一个Android事件发布/订阅轻量级框架,可以代替Android传统的Intent,Handler,Broadcast或接口函数,在Fragment,Activity,Service线程之间传递数据,执行方法。
ViewModel:Model-View-ViewModel,MVVM。它本质上就是MVC的改进版。MVVM就是将其中的View的状态和行为抽象化,MVVM框架的由来便是MVP(Model-View-Presenter)模式与WPF结合的应用方式时发展演变过来的一种新型架构框架。它立足于原有MVP框架并且把WPF的新特性糅合进去,以应对客户日益复杂的需求变化。
Start Activity For Result:Android***原生支持的跨页面通信方式,有着简单易用的优点,但不支持实时通信。
安卓(Android)是一种基于Linux内核的自由及开放源代码的操作***。主要使用于移动设备,如智能手机和平板电脑,Android应用开发中有很多组件间的通信方式,诸如Start Activity For Result,ViewModel和EventBus等,Start Activity For Result是Android***原生支持的跨页面通信方式,简单易用,但只能在相邻的两个打开的Activity间通信,不支持实时通信。如图1所示,ViewModel支持在一个Activity中的组件双向的实时通信,但是不支持多个活动(Activity)之间的组件通信。EventBus支持在多个Activity之间的组件的实时通信,但需要开发人员代码保证Activity生命周期结束后取消订阅,实施繁琐,且代码编写耦合程度高。
本公开实施例所提供的双向通信方案选用了Androidx下的ViewModel,其原始能力支持组件间的通信。多组件实时通信我们使用了Androidx下的ViewModel,其原始能力支持组件间的通信,但是由于ViewModel一般存放于ViewModelStore中,而ViewModelStore又保存于Activity或Fragment中,其生命周期和保存在的Activity或Fragment一致。
如图2,本公开实施例提供一种双向通信方法,包括如下步骤。
S201,确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识。
具体实施时,当第一进程要与第二进程进行通信时,便在周期表中分别加入第一进程与第二进程对应的标识,当然,在确定其他进程将与周期表中存在对应标识的进程进行通信时,在周期表中加入该进程的标识。
S202,基于双向通信进程,使得第一进程与第二进程进行通信。
具体实施时,在S201步骤中添加完第一进程和第二进程对应的标识后,也就是说,周 期表中存在第一进程的标识和第二进程的标识后,使第一进程与第二进程进行通信,当然,如果第三进程要与第一进程进行通信,在周期表中存在第三进程对应的标识之后,使得第一进程与第三进程进行通信。
需要说明的是,如果第一进程与第二进程通信的同时,第三进程与第一进程也进行通信,此时第二进程和第三进程之间可以直接通信或经由第一进程间接通信,也可以使得第二进程和第三进程之间不通信,本公开实施例对此不做限定。
S203,确定任一进程停止通信时,在周期表中删除任一进程对应的标识。
具体实施时,在确定任意一个进程停止使用双向通信时,在周期表中删除该进程对应的标识,在周期表中没有进程对应的标识时,停止双向通信进程,并删除双向通信进程和周期表。用以在不需要双向通信时清空内存,节省***资源。
本公开实施例提供的双向通信方法中,确定第一进程与第二进程进行通信时,分别在周期表中添加第一进程和第二进程对应的标识,然后使得第一进程与第二进程进行通信,并在任一进程停止使用时,从周期表中将其对应的标识删掉。实现了进程之间的实时通信,提高了通信效率,节省***资源。
本公开实施例提供的双向通信方法中,在确定第三进程进行双向通信后,将第三进程对应的标识加入周期表中,实现了多进程间的实时通信,提升通信效率。
本公开实施例提供的双向通信方法中,双向通信进程生成于共享区域内,不受进程生命周期的影响,提高了通信效率。
具体来说,以图3图4为例,对本公开实施例进行详细说明。
如图3所示,为本公开实施例提供的一种双向通信方法,该方法包括如下步骤。
S301,确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识。
具体实施时,首先自定义ClearUselessViewModelObserver并实现LifecycleEventObserver接口。给ClearUselessViewModelObserver传入lifecycle对象和map对象,然后实现LifecycleEventObserver接口的onStateChanged方法,此方法在参数LifecycelEvent为Event.DESTROYED时将上一步的lifecycle从map对应的value中移除。
在上述准备工作完成后,便将第一进程的进程名和第二进程的进程名加入lifecycle。
S302,基于双向通信进程,使得第一进程与第二进程进行通信。
具体实施时,检测到lifecycle中拥有第一进程的进程名和第二进程的进程名,便让第 一进程与第二进程进行viewmodel通信。
S303,确定任一进程停止通信时,在周期表中删除任一进程对应的的标识。
具体实施时,在进程停止使用viewmodel通信时,将该进程的进程名从lifecycle中删除。
通过使用本实施例提供的双向通信方法,可以使得进程利用viewmodel进行通信,且基于周期表,保证进程停止通信后导致viewmodel关闭后,扔留存进程信息,在其他进程进行通信时启用新的viewmodel后可以直接进行通信,但该方案需要多次进行viewmodel的开启与关闭,不利于具体实施,所以如图4所示,本公开实施例提供另一双向通信方法,具体步骤如下。
S401,确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识。
具体实施时,如图5所示,为本公开实施例所提供的代码结构类UML图,首先自定义ClearUselessViewModelObserver并实现LifecycleEventObserver接口。给ClearUselessViewModelObserver传入lifecycle对象和map对象,然后实现LifecycleEventObserver接口的onStateChanged方法,此方法在参数LifecycelEvent为Event.DESTROYED时将上一步的lifecycle从map对应的value中移除。
然后给SharedViewModelProvider传入store对象和map对象,并.实现get方法,将方法传入参数lifecycle,class等。通过调用ViewModelProvider的super.get方法获取并创建viewmodel。将创建的viewmodel放入store中,将传入的lifecycle放入map的value中,同时新建一个ClearUselessViewModelObserver对象并调用lifecycle的addObserver方法传入该ClearUselessViewModelObserver对象。
通过上述步骤即可调用SharedViewModelProvider的get方法获取ViewModeld对象,获取到的ViewModel对象会自动感知传入的Lifecycle对象生命周期,在生命周期结束后销毁。上述具体调用过程如图6所示。
在上述准备工作完成后,便将第一进程的进程名和第二进程的进程名加入lifecycle。
S402,基于双向通信进程,使得第一进程与第二进程进行通信。
具体实施时,检测到lifecycle中拥有第一进程的进程名和第二进程的进程名,便让第一进程与第二进程进行viewmodel通信。
S403,确定任一进程停止通信时,在周期表中删除任一进程对应的的标识。
具体实施时,在进程停止使用viewmodel通信时,将该进程的进程名从lifecycle中删除。当map中的value的内容为空时,将viewmodel从store中移除。
应用本公开实施例所提供的方案后,如图7所示,为使用共享空间进行viewmodel通信时的示意图。本实施例中在SharedViewModel中新增了一种ViewModelStore,其生命周期不再跟随某一Activity和Fragment,而是和Android Application生命周期一致,即在App运行期间都可以通过此ViewModelStore获取到相同实例的ViewModel。其次,SharedViewModel中维护了一个引用列表,这个列表中记录了ViewModel实例和使用了该ViewModel实例的Lifecycle实例,当有新的Lifecycle使用了该ViewModel时会记录该Lifecycle实例到列表中。当记录的Lifecycle实例生命周期结束到DESTROYED状态后会将此Lifecycle实例从列表中移除,当所有Lifecycle实例均从列表中移除后会释放此ViewModel。提升了通信的效率。
图8为本公开实施例提供的一种双向通信装置,包括:添加单元801,用于确定第一进程与第二进程将进行通信后,在周期表中加入第一进程对应的标识和第二进程对应的标识;通信单元802,用于基于双向通信进程,使得第一进程与第二进程进行通信;以及删除单元803,用于确定任一进程停止通信时,在周期表中删除任一进程对应的的标识。
在一种可能的实施方式中,本公开实施例提供的装置中,添加单元801还用于:确定第三进程与周期表中任一标识对应的目标进程将进行通信后,在周期表中加入第三进程对应的标识;以及通信单元802还用于:基于双向通信进程,使得第三进程与目标进程进行通信。
在一种可能的实施方式中,本公开实施例提供的装置中,通信单元802还用于:在周期表中没有进程对应的标识时,停止双向通信进程。
在一种可能的实施方式中,本公开实施例提供的装置中,删除单元803还用于:删除双向通信进程和周期表。
在一种可能的实施方式中,本公开实施例提供的装置中,双向通信进程是在共享区域内生成的。
另外,结合图1-图8描述的本公开实施例的双向通信方法和装置可以由电子设备来实现。图9示出了本公开实施例提供的电子设备的硬件结构示意图。
电子设备可以包括处理器901以及存储有计算机程序指令的存储器902。
具体地,上述处理器901可以包括中央处理器(CPU),或者特定集成电路(Application  Specific Integrated Circuit,ASIC),或者可以被配置成实施本公开实施例的一个或多个集成电路。
存储器902可以包括用于数据或指令的大容量存储器。举例来说而非限制,存储器902可包括硬盘驱动器(Hard Disk Drive,HDD)、软盘驱动器、闪存、光盘、磁光盘、磁带或通用串行总线(Universal Serial Bus,USB)驱动器或者两个或更多个以上这些的组合。在合适的情况下,存储器902可包括可移除或不可移除(或固定)的介质。在合适的情况下,存储器902可在数据处理装置的内部或外部。在特定实施例中,存储器902是非易失性固态存储器。在特定实施例中,存储器902包括只读存储器(ROM)。在合适的情况下,该ROM可以是掩模编程的ROM、可编程ROM(PROM)、可擦除PROM(EPROM)、电可擦除PROM(EEPROM)、电可改写ROM(EAROM)或闪存或者两个或更多个以上这些的组合。
处理器901通过读取并执行存储器902中存储的计算机程序指令,以实现上述实施例中的任意一种推荐信息的确定方法。
在一个示例中,电子设备还可包括通信接口903和总线910。其中,如图9所示,处理器901、存储器902、通信接口903通过总线910连接并完成相互间的通信。
通信接口903,主要用于实现本公开实施例中各模块、装置、单元和/或设备之间的通信。
总线910包括硬件、软件或两者,将电子设备的部件彼此耦接在一起。举例来说而非限制,总线可包括加速图形端口(AGP)或其他图形总线、增强工业标准架构(EISA)总线、前端总线(FSB)、超传输(HT)互连、工业标准架构(ISA)总线、无限带宽互连、低引脚数(LPC)总线、存储器总线、微信道架构(MCA)总线、***组件互连(PCI)总线、PCI-Express(PCI-X)总线、串行高级技术附件(SATA)总线、视频电子标准协会局部(VLB)总线或其他合适的总线或者两个或更多个以上这些的组合。在合适的情况下,总线910可包括一个或多个总线。尽管本公开实施例描述和示出了特定的总线,但本公开考虑任何合适的总线或互连。
该电子设备可以基于接收到的智能设备发送的服务请求,执行本公开实施例中的双向通信方法,从而实现结合图1-图8描述的双向通信方法和装置。
另外,结合上述实施例中的双向通信方法,本公开实施例可提供一种计算机可读存储介质来实现。该计算机可读存储介质上存储有计算机程序指令;该计算机程序指令被处理 器执行时实现上述实施例中的任意一种双向通信方法。
需要说明的是,在本文中,诸如“第一”和“第二”等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述仅是本公开的具体实施方式,使本领域技术人员能够理解或实现本公开。对这些实施例的多种修改对本领域的技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本公开的精神或范围的情况下,在其它实施例中实现。因此,本公开将不会被限制于本文所述的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。

Claims (14)

  1. 一种双向通信方法,包括:
    确定第一进程与第二进程将进行通信后,在周期表中加入所述第一进程对应的标识和所述第二进程对应的标识;
    基于双向通信进程,使得所述第一进程与所述第二进程进行通信;
    确定任一进程停止通信时,在所述周期表中删除所述任一进程对应的的标识。
  2. 如权利要求1所述的方法,还包括:
    确定第三进程与所述周期表中任一标识对应的目标进程将进行通信后,在所述周期表中加入所述第三进程对应的标识;
    基于所述双向通信进程,使得所述第三进程与所述目标进程进行通信。
  3. 如权利要求1所述的方法,还包括:
    在所述周期表中没有进程对应的标识时,停止所述双向通信进程。
  4. 如权利要求3所述的方法,其中,在停止所述双向通信进程之后,所述方法还包括:
    删除所述双向通信进程和所述周期表。
  5. 如权利要求1所述的方法,其中,所述双向通信进程是在共享区域内生成的。
  6. 一种双向通信装置,包括:
    添加单元,用于确定第一进程与第二进程将进行通信后,在周期表中加入所述第一进程对应的标识和所述第二进程对应的标识;
    通信单元,用于基于双向通信进程,使得所述第一进程与所述第二进程进行通信;
    删除单元,用于确定任一进程停止通信时,在所述周期表中删除所述任一进程对应的的标识。
  7. 如权利要求6所述的装置,其中,所述添加单元还用于:
    确定第三进程与所述周期表中任一标识对应的目标进程将进行通信后,在所述周期表中加入所述第三进程对应的标识;
    所述通信单元还用于:基于所述双向通信进程,使得所述第三进程与所述目标进程进行通信。
  8. 如权利要求6所述的装置,其中,所述通信单元还用于:
    在所述周期表中没有进程对应的标识时,停止所述双向通信进程。
  9. 如权利要求8所述的装置,其中,所述删除单元还用于:
    删除所述双向通信进程和所述周期表。
  10. 如权利要求6所述的装置,其中,所述双向通信进程是在共享区域内生成的。
  11. 一种双向通信设备,包括:
    存储器;
    处理器;以及
    计算机程序;
    其中,所述计算机程序存储在所述存储器中,并被配置为由所述处理器执行以实现如权利要求1-5中任一项所述的方法。
  12. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1-5中任一项所述的方法。
  13. 一种计算机程序产品,包括指令,所述指令当由处理器执行时实现如权利要求1-5中任一项所述的方法。
  14. 一种计算机程序,包括指令,所述指令当由处理器执行时实现如权利要求1-5中任一项所述的方法。
PCT/CN2022/133223 2021-11-25 2022-11-21 一种双向通信方法、装置、设备及介质 WO2023093675A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111413623.8A CN116166448A (zh) 2021-11-25 2021-11-25 一种双向通信方法、装置、设备及介质
CN202111413623.8 2021-11-25

Publications (1)

Publication Number Publication Date
WO2023093675A1 true WO2023093675A1 (zh) 2023-06-01

Family

ID=86413705

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/133223 WO2023093675A1 (zh) 2021-11-25 2022-11-21 一种双向通信方法、装置、设备及介质

Country Status (2)

Country Link
CN (1) CN116166448A (zh)
WO (1) WO2023093675A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109933443A (zh) * 2019-03-07 2019-06-25 腾讯科技(深圳)有限公司 进程间通信方法、装置、计算机设备及可读存储介质
US10846117B1 (en) * 2015-12-10 2020-11-24 Fireeye, Inc. Technique for establishing secure communication between host and guest processes of a virtualization architecture
CN112764946A (zh) * 2021-01-08 2021-05-07 重庆创通联智物联网有限公司 跨进程数据传输方法、装置、电子设备和存储介质
CN113495795A (zh) * 2020-04-03 2021-10-12 华为技术有限公司 一种进程间通信方法及相关设备
WO2021217529A1 (zh) * 2020-04-29 2021-11-04 华为技术有限公司 一种进程间通信的方法及***

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10846117B1 (en) * 2015-12-10 2020-11-24 Fireeye, Inc. Technique for establishing secure communication between host and guest processes of a virtualization architecture
CN109933443A (zh) * 2019-03-07 2019-06-25 腾讯科技(深圳)有限公司 进程间通信方法、装置、计算机设备及可读存储介质
CN113495795A (zh) * 2020-04-03 2021-10-12 华为技术有限公司 一种进程间通信方法及相关设备
WO2021217529A1 (zh) * 2020-04-29 2021-11-04 华为技术有限公司 一种进程间通信的方法及***
CN112764946A (zh) * 2021-01-08 2021-05-07 重庆创通联智物联网有限公司 跨进程数据传输方法、装置、电子设备和存储介质

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
BUG MIAO: "Inter-component Communication Scheme (6): Automatic Perception of Life Cycle Event Bus LiveDataBus", BLOG.CSDN.NET/BUGYINYIN, CN, 9 January 2021 (2021-01-09), CN, pages 1 - 5, XP093069171, Retrieved from the Internet <URL:https://blog.csdn.net/bugyinyin/article/details/112393945> [retrieved on 20230801] *
LAP CHEN: "Core Principle of EventBus Can Actually be Understood by Saving These Three Pictures, Collect Same)", ZHUANLAN.ZHIHU.COM/, CN, 18 June 2020 (2020-06-18), CN, pages 1 - 4, XP093069163, Retrieved from the Internet <URL:https://zhuanlan.zhihu.com/p/149176367> [retrieved on 20230801] *
YANG XU: "Android Architecture Components Official Document 03-ViewModel", SEGMENTFAULT.COM, CN, 2 July 2018 (2018-07-02), CN, pages 1 - 4, XP093069175, Retrieved from the Internet <URL:https://segmentfault.com/A/1190000015453015> [retrieved on 20230801] *

Also Published As

Publication number Publication date
CN116166448A (zh) 2023-05-26

Similar Documents

Publication Publication Date Title
US20150127755A1 (en) Method and apparatus for checking status of messages in electronic device
CN108427649B (zh) Usb接口的接入管理方法、终端设备、***及存储介质
US9549316B2 (en) Host device coupled to a mobile phone and method of operating the same
JP6101360B2 (ja) アプリケーションの状態を設定するための方法、装置、プログラム及び記録媒体
WO2021208512A1 (zh) 用户界面的控件信息的获取方法、装置、终端及存储介质
US11269663B2 (en) Method and apparatus for adapting handle device to third-party application, and storage medium
US20150339242A1 (en) Method and apparatus for transmitting data in android platform based terminal device
TW201518933A (zh) 測試裝置及其測試方法
WO2018209958A1 (zh) 可升级文件的升级方法、机顶盒和存储介质
US10691390B2 (en) Method and device for video rendering
CN105138693A (zh) 一种访问数据库的方法及装置
CN110945475A (zh) 用于提供可打补丁的rom固件的***和方法
WO2019019713A1 (zh) 检测应用程序内存泄露的方法、终端及可读存储介质
WO2016015531A1 (zh) 一种信息处理方法及装置
CN110766379A (zh) 一种业务流程的处理方法、装置、介质和电子设备
WO2023104146A1 (zh) 原子性保持方法、处理器及电子设备
US8453149B2 (en) Efficient multi-core processing of events
CN103559166A (zh) 一种多核之间的高速数据传输的方法
WO2023093675A1 (zh) 一种双向通信方法、装置、设备及介质
CN110569308A (zh) 一种数据文件组装方法、装置、设备及储存介质
TW201814546A (zh) 設備的組件加載方法、裝置以及物聯網系統
CN105975306A (zh) 电子设备的应用程序启动管理方法和装置
CN112017330B (zh) 智能锁参数配置方法、装置、智能锁及存储介质
CN105100901A (zh) 一种虚拟存储卡配置方法及***
CN114791854B (zh) 用户态虚拟机任务的调度方法、装置、设备及存储介质

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: 22897758

Country of ref document: EP

Kind code of ref document: A1