<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ModuleBus通信模塊封裝同步

          聯(lián)合創(chuàng)作 · 2023-10-02 01:50

          ModuleBus

          用法上面盡可能靠近 EventBus,大小大概54K沒(méi)做任何壓縮。

          已經(jīng)上傳到 JCenter 了,可以直接調(diào)用

          添加 ModuleBus 到你的項(xiàng)目

          Gradle:

          compile 'com.cangwang.core:modulebus:1.0.1'

          簡(jiǎn)單介紹一下

          需要自己定義一個(gè) Client 用于傳輸,需要繼承于 IBaseClient

          然后 ModuleEvent 的 coreClientClass 用于指定對(duì)應(yīng)的 Client,然后添加實(shí)現(xiàn)的方法,方法名任意都可以。

          然后 register 和 unregister 的方法都和 EventBus 的用法是一樣的

          post 的方法需要填寫第一個(gè)參數(shù)為 client.class,第二個(gè)參數(shù)是方法名,之后的參數(shù)為方法的參數(shù)。

          ModuleBus in 3 steps

          1. Define events:

            public static class MessageClient extend IBaseClient { /* Additional fields if needed */ }
          2. Prepare ModuleEvent and function: Declare and annotate your subscribing method.

            @ModuleEvent(coreClientClass = MessageClient.Class)  
            public void fun(Object...args) {/* Do something */};

            Register and unregister your ModuleBus. For example on Android, activities and fragments should usually register according to their life cycle:

            @Override
            public void onStart() {
                super.onStart();
                ModuleBus.getInstance().register(this);
            }
            
            @Override
            public void onDestroy() {
                super.onStop();
                ModuleBus.getInstance().unregister(this);
            }
          3. Post function:

            ModuleBus.getInstance().post(MessageClient.class,"fun",Object...args);

          這里需要在 base 的 module 去添加依賴 modulebus ,然后其他需要交互的模塊依賴于 base。

          例子里面會(huì)有簡(jiǎn)單的演示,只要下載之后就能看到源碼和調(diào)用了。我也會(huì)封裝越來(lái)越好用得功能到里面。

          瀏覽 14
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  99视频一区大学生 | 青草mv| 亚洲AV成人无码精在线 | 亚洲A无 亚洲俺也 | 日韩A片特黄 |