Dagger2: Using CompositeDisposable with Android Paging Library

。_饼干妹妹 提交于 2021-02-11 14:18:04

问题


I'm using Dagger2.

I will be injecting CompositeDisposable in ViewModel through @Inject constructor(private val compositeDisposable: CompositeDisposable)

And my screen would also be using Android Pagination library and inside PageKeyedDataSource class I would be adding every network call into compositeDisposable using it's .add(diposable). I also would be adding CompositeDisposable in PageKeyedDataSource constructor through Dagger graph.

Is there any way that CompositeDisposable in ViewModel constructor and PageKeyedDataSource refer to same object so that I can clear all disposables using following construct?

override fun onCleared() {
    compositeDisposable.clear()
    super.onCleared()
}

This is useful for me if some network call is in progress and user hits back button. I would like to dispose all network calls through onCleared() method.

来源:https://stackoverflow.com/questions/62595956/dagger2-using-compositedisposable-with-android-paging-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!