2017-09-23 50 views
0

我想使用RxAndroid和RxJava,但我有點困惑哪些下面提到的庫我應該使用? 在一些教程它們使用例如以下類其可在哪個庫我應該使用RxAndroid和RxJava

compile 'io.reactivex:rxandroid:1.2.1' 
compile 'io.reactivex:rxjava:1.1.9' 

.subscribe(new Subscriber<String>) 

和一些教程哎使用例如它們使用下列類,其是可以在以下的lib

compile 'io.reactivex.rxjava2:rxjava:2.0.1' 
compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 

.subscribe(new Observer<String>) 

    moreover, in this lib there is no "Unsubscribe()" method??!! 

和在觀察者類有一些所謂的一次性類
這不Subscriber類存在

此外, 請讓我知道我應該使用哪一個?

compile 'io.reactivex:rxandroid:1.2.1' 
compile 'io.reactivex:rxjava:1.1.9' 

compile 'io.reactivex.rxjava2:rxjava:2.0.1' 
compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
+0

https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0。您可以使用Disposable並調用dispose()。 – Raghunandan

回答

0

在我的新項目中,我使用

compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
compile 'io.reactivex.rxjava2:rxjava:2.1.0' 
+0

但在這個庫你提到有沒有退訂方法..對吧? – user2121

+0

你認爲一次性,你應該處置它或使用CompositeDisposable信件處置幾個一次性 CompositeDisposable compositeDisposable = new CompositeDisposable(); compositeDisposable.add(一次性的); compositeDisposable.clear(); –

0

有兩個主要版本Rxjava和RxAndroid的,基本上如果你使用的第一個版本(1。 xy)你應該遷移到使用Rxjava2。 其原因是來自官方的github回購

時間表計劃1.x的行:

  • 2017年6月1日 - 特性凍結(沒有新的運營商),只有錯誤修正三月
  • 31,2018 - 結束生命的,沒有進一步的發展

,如果你從頭開始,你應該使用版本2,因爲它比更強大舊的,它有背壓支持,試着看看回購和維基here

0

如果你開始新項目,你應該使用RxJava2,因爲它更快,更優化。有一種特殊的類型來處理箱子的背壓。但它裏面有更多的方法。 一次性只是Subscription類的新名稱。所以在RxJava1中它是Subscription.unsubscribe()現在它的Disposable.dispose()。