android - PublishSubject doOnSubscribe not called -


i have publishsubject registered doonsubscribe , doonunsubscribe actions. both actions not called, if subscription done.

private publishsubject<long> publishsubject; private subscription subscription;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);          publishsubject = publishsubject.create();     publishsubject.doonsubscribe(new action0() {         @override         public void call() {             log.d("subject", "someone subscribed.");         }     });     publishsubject.doonunsubscribe(new action0() {         @override         public void call() {             log.d("subject", "someone unsubscribed.");         }     });      observable.interval(1, timeunit.seconds).subscribe(new action1<long>() {         @override         public void call(final long tick) {             publishsubject.onnext(tick);         }     }); }  @override protected void onresume() {     super.onresume();     subscription = publishsubject.subscribe(new action1<long>() {         @override         public void call(final long along) {             log.d("subject", "got tick " + along);         }     }); }  @override protected void onpause() {     super.onpause();     subscription.unsubscribe(); } 

but in logcat, "got tick " message , no "someone subscribed".

07-25 17:57:34.110 8753-8965/com.example.plinzen.myapplication i/openglrenderer: initialized egl, version 1.4 07-25 17:57:34.954 8753-8964/com.example.plinzen.myapplication d/subject: got tick 0 07-25 17:57:35.950 8753-8964/com.example.plinzen.myapplication d/subject: got tick 1 07-25 17:57:36.950 8753-8964/com.example.plinzen.myapplication d/subject: got tick 2 07-25 17:57:37.950 8753-8964/com.example.plinzen.myapplication d/subject: got tick 3 07-25 17:57:38.949 8753-8964/com.example.plinzen.myapplication d/subject: got tick 4 07-25 17:57:39.950 8753-8964/com.example.plinzen.myapplication d/subject: got tick 5 

any idea, why these actions not called, when subscribing in onresume() , unsubscribing in onpause()? misunderstand subject topic?

don't break chain:

private observable<long> publishedobservable;  [...]  publishsubject<long> publishsubject = publishsubject.create(); publishedobservable = publishsubject.doonsubscribe(new action0() {     @override     public void call() {         log.d("subject", "someone subscribed.");     } }).doonunsubscribe(new action0() {     @override     public void call() {         log.d("subject", "someone unsubscribed.");     } }); 

and in other methods use publishedobservable.

see, in code create 2 new observables, throw them away directly; .dofoobar methods not modify observable, create new 1 implements desired behavior.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -