# ActiveDatabus **Repository Path**: xzj1989/active-databus ## Basic Information - **Project Name**: ActiveDatabus - **Description**: 鸿蒙通信组件 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-05-31 - **Last Updated**: 2021-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ####功能说明 1.发送消息 2.发送延时消息 3.发送生命周期感知消息,只有在传入的生命周期初始化以后才会发送,否则取消发送 4.发送广播消息 5.支持消息回调跟随Ability生命周期,slice生命周期,内置生命周期(需手动移除观察者) 6.消息回调线程配置,包括主线程,后台线程与默认线程 7.支持黏性消息,先发送再注册消息回调,之前发送的消息可以收到 8.应用处于后台时是否接收消息配置 ####使用方法 1.发送消息 LiveEventBus .get("key") .post(value); 2.发送延时消息 ActiveDataBus.get("key").postDelay(value, delay); 3.发送生命周期感知消息 ActiveDataBus.get("key").post(lifeCycleOwner, value); 4.发送广播消息 IntentParams intentParams = new IntentParams(); intentParams.setParam("test", "hello"); new BroadcastPublishHelper.EventPublishBuild(new Intent.OperationBuilder().withAction("action").build()) .withIntentParams(intentParams).build().publishEvent(); 5.消息回调配置ability生命周期或slice生命周期 ActiveDataBus.get("key",value.class).observe(lifeCycleOwner, value -> { }); 6.消息回调配置内置生命周期与移除观察者 Observer observer = value -> {} ActiveDataBus.get("key",value.class).observeForever(observer); ActiveDataBus.get("key",value.class).removeObserver(observer); 7.消息回调线程配置 ActiveDataBus.get(mainTest, String.class).withThreadMode(ThreadMode.MAIN).observe(this, s -> { }); 8.消息回调到后台线程配置线程池 ActiveDataBus.config().setThreadPoolExecutor(Executors.newFixedThreadPool(3)); 9.消息回调黏性配置 ActiveDataBus.get("key",value.class).withSticky(true/false).observe(this, t -> { }); 10.配置应用处于后台时是否可以收到消息 ActiveDataBus.get(alwaysTest).withBackground(true).observe(this, t -> { }); 11.广播消息回调 BroadCastManager.getInstance().registerCommonEvent(o -> { }, "action", lifeCycleOwner); ####注意事项 1.广播消息的黏性配置设置为true以后不能更改,更改也不生效