I have a very simple RXJava emitter. It is a publishSubject actually but its job to convert Integers to strings and update a UI element afterwards when it subscribes. The code looks like this :
PublishSubject integerToStringEmitter = PublishSubject.create();
Subscription mysingle= Single.just(4).map(new Func1<Integer, String>() {
@Override
public String call(Integer integer) {
return String.valueOf(integer);
}
}).subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
tv.setText(s);
}
});
// integerToStringEmitter.subscribe(); //it still emits even without this, why ?
What i want to happen: for subscription to only begin when i call integerToStringEmitter.subscribe();
What is happening currently : As soon as i launch the program the onNext is getting called and the UI element is being set to the # 4. why ? i need more control over this thing so it does not execute right away without me even subscribing to it. Please help solve.