I am using RxAndroid observable to retrieve some object (String in this case). My service looks like this:
public Observable<String> getRandomString() { return Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) {
I subscribe to my presenter and post the result:
public void loadRandomString() { Observable<String> observable = mService.getRandomString(); observable .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.newThread()) .subscribe(new Subscriber<String>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { mMainView.onError(e.getLocalizedMessage()); } @Override public void onNext(String string) {
This works fine and thatβs it, but I want this operation to be periodic (every x minutes). I could use Timer or ScheduledThreadPoolExecutor to do this over and over, but I would like to see if there is any solution in the RxAndroid area. I have found some old solutions since 2013, but many of them are out of date now. Is this possible using some kind of recursion, or can I achieve this in a more elegant way?
Thanks in advance!
source share