RXJava计时器返回订阅,其中Action1使用Long类型。 我需要另一个传递另一种类型的Action1对象。
Observable<Long> observable = Observable.timer(7, TimeUnit.SECONDS, Schedulers.computation());
cancelOrderSubscription = observable
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
// NOT LONG REQUIRED
}
});
答案 0 :(得分:1)
基于akarnokd评论。
Observable.timer(5, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.map(new Func1<Long, MyOrderStorageItem>() {
@Override
public MyOrderStorageItem call(Long aLong) {
return myOrderStorageItem;
}
})
.subscribe(new Action1<MyOrderStorageItem>() {
@Override
public void call(MyOrderStorageItem myOrderStorageItem) {
// use object myOrderStorageItem
}
});