我想知道如何忽略异常并继续无限流(在我的情况下是位置流)?
我正在获取当前用户位置(使用Android-ReactiveLocation),然后将它们发送到我的 API(使用Retrofit)。
在我的情况下,当网络调用(例如超时)期间发生异常时,调用onError
方法并且流自行停止。如何避免?
活动:
private RestService mRestService;
private Subscription mSubscription;
private LocationRequest mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(100);
...
private void start() {
mRestService = ...;
ReactiveLocationProvider reactiveLocationProvider = new ReactiveLocationProvider(this);
mSubscription = reactiveLocationProvider.getUpdatedLocation(mLocationRequest)
.buffer(50)
.flatMap(locations -> mRestService.postLocations(locations)) // can throw exception
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
}
休息服务:
public interface RestService {
@POST("/.../")
Observable<Response> postLocations(@Body List<Location> locations);
}