1. Execute multiple task sequencly (WAY-1)
------------------------------------------------------------------------------
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
public class TestClass2 {
public static void main(String[] args){
Observable<String> myObservable = Observable.create(
new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> sub) throws Exception {
// "Emit" any data to the subscriber
sub.onNext(showData("a"));
sub.onNext(showData("b"));
sub.onNext(showData("c"));
// Trigger the completion of the event
sub.onComplete();
}
});
myObservable.subscribe();
}
public static String showData(String msg){
System.out.println(msg);
return msg;
}
}
2. Execute multiple task sequencly (WAY-2)
--------------------------------------------------------------------------------
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
public class TestClass3 {
public static void main(String[] args){
Observer<String> mySubscriber = new Observer<String>() {
@Override
public void onSubscribe(Disposable disposable) {
System.out.println("onSubscribe");
}
@Override
public void onNext(String s) {
System.out.println("onNext: " + s);
}
@Override
public void onError(Throwable throwable) {
System.out.println("Error");
}
@Override
public void onComplete() {
System.out.println("done!");
}
};
mySubscriber.onNext("a");
mySubscriber.onNext("b");
mySubscriber.onNext("c");
mySubscriber.onComplete();
}
}