Reputation: 8397
I'm trying to learn RxJava2 for Android using kotlin and I'm following an this good online tutorial. First I added this two lines the gradle.build file:
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
The I tried to implement the Observable pattern with this code:
import io.reactivex.Observable
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val observable = Observable.from(arrayOf(1, 2, 3, 4, 5, 6))
}
}
This is supposed to work easily, but I cannot call from() operator on the Observable (Unresolved reference: from). So basically I'am stuck before I even started. Does any one have any idea what i did wrong?
Upvotes: 2
Views: 785
Reputation: 1640
Besides from*
methods there are also extension functions for lists/arrays in rx-kotlin, so you might call for example listOf(...).toObservable()
Upvotes: 1
Reputation: 25573
from
was removed in RxJava2 because it had a lot of overloads which might make it not behave as you would expect. It has been split into specific methods like fromArray
or fromIterable
.
Upvotes: 5