RePlugin
RePlugin copied to clipboard
插件使用LiveData无法监听到数据变化
原因是LifecycleRegistry的状态没有改变,至于是什么引起的状态没有改变还没有找到,我暂时的处理方案是在activity或fragment的生命周期方法里手动调一下LifecycleRegistry的handleLifecycleEvent()方法,设置给相应的值。 如在onStart中调用:getLifecycle().handleLifecycleEvent(Lifecycle.Event.ON_START);
项目中完全使用LiveData这一套,Fragment中是可以监听到回调的,activity中不行,非常不便。
observerFovever可以,不知道会不会衍生其他问题
这个问题解决了吗?
谢谢啦,问题原因找到了
在 2019-04-02 14:18:53,"Jack" [email protected] 写道:
这个问题解决了吗?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
谢谢啦,问题原因找到了 在 2019-04-02 14:18:53,"Jack" [email protected] 写道: 这个问题解决了吗? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
请问你怎么解决的,我的插件独立运行没问题,宿主运行走不进lifecycleobserver,添加了handleLifecycleEvent也没用
我这边也有这个问题,后面发现是宿主中依赖中添加了implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0',在这个库中有一个lifecycle-process的模块,这个模块是监听整个App的生命周期的,比如App处于前台或者后台如果不需要监听App生命周期,可以在宿主中将该模块移除,我这边是这样处理的 implementation ('androidx.lifecycle:lifecycle-extensions:2.2.0'){ exclude group:'androidx.lifecycle',module:'lifecycle-process' }