问题
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