I have a retrofit observable:
@GET("something/")
Observable<Something> getSomething();
subscribing to it gives the response.
getSomething().subscribe(new Subscriber<Something>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Something something) {
//update database of something
}
});
how can i make this call every 60 seconds so that i can update database accordingly?
First please don't do it if you can avoid it. It's preferable to push the changes (GCM for example) instead of pulling to save battery and data.
To do this you can use a combination of Observable.interval
and the Observable.repeat
operator.
Observable.interval(60, TimeUnit.SECONDS)
.flatMap(n -> getSomething())
.repeat()
.subscribe();
Sorry about the lambdas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With