网站备案查询 美橙,不会写代码怎么做网站,wordpress版本怎么升级,石家庄工程官网因为好几次自己想要在别的项目使用#xff0c;每次都要重写一遍太麻烦#xff0c;整理了一下发布到 jcenter 。利用官方lifecycle库与kotlin语言特性。lifecycle官方 support 27 自带。库代码数少于100行。用法#xff1a;1、添加依赖implementation com.sjianjun:rxutils:1…因为好几次自己想要在别的项目使用每次都要重写一遍太麻烦整理了一下发布到 jcenter 。利用官方lifecycle库与kotlin语言特性。lifecycle官方 support 27 自带。库代码数少于100行。用法1、添加依赖implementation com.sjianjun:rxutils:1.0.22、代码提供了3个Disposable的扩展方法这里使用destory演示。class MainActivity : AppCompatActivity(), AutoDisposeEnhance {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)//Observable.create { }.doOnDispose {Log.e(dispose, Exception(测试检查调用栈))}.subscribe().destroy(lifecycle lifecycle)//destroy 方法的参数由 接口 sjj.rx.AutoDisposeEnhance 提供 。Observable.create { }.doOnDispose {Log.e(dispose2, Exception(测试检查调用栈))}.subscribe().destroy()}override fun onResume() {super.onResume()}}说明interface AutoDisposeEnhance {fun Disposable.destroy(onceKey: String? null) {destroy(onceKey, getLifecycle())}fun Disposable.stop(onceKey: String? null) {stop(onceKey, getLifecycle())}fun Disposable.pause(onceKey: String? null) {pause(onceKey, getLifecycle())}fun getLifecycle():Lifecycle}主要声明了三个方法扩展destory、stop、pause参数 oncekey 如果重复的话会直接取消之前的disposeable 如果为null 则不处理参数lifecycle 被绑定到的声明周期对象通常由 activity 或者 fragment 提供也可以自定义。destory stop pause 三个扩展方法表示在相应的生命周期 取消订阅。