Reputation: 397
This is a typical network call using rxjava
(and retrofit
). Can JobScheduler
be used to replace this? If yes, how? Above all, is it recommended?
Observable<GenericResponse> observable = someInterface.someMethod();
observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<GenericResponse>() {
@Override
public void onCompleted() {
Log.d(TAG, "Success");
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "Error: ", e);
}
@Override
public void onNext(GenericResponse genericResponse) {
Log.d(TAG, "onNext");
}
});
Upvotes: 1
Views: 1019
Reputation: 56
Big No. The JobScheduler API schedules job which will be executed only when certain conditions that you define is met.
Upvotes: 1
Reputation: 13450
Short answer: No
Long: The JobScheduler API aims on creating background processes under some conditions (charging phone, network type etc...) usually when the phone is switched off. RxJava is a reactive library that can be used WITH JobScheduler -if you like - and anywhere in your code to facilitate how things are happening.
Upvotes: 1