android - How to stop an RxJava observable from emitting items. Tried to unsubscribe but it kept going -


in code create observable , keep reference subscription object. when start app prints numbers 1 1000000 if minimize activity, ubsubscribe subscription in onpause however, logcat keeps printing numbers. how stop doing so?

public class mainactivity extends appcompatactivity {      private subscription printingnumbers;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          printingnumbers = observable                           .range(1, 500000)                           .map(i -> i*2)                           .subscribe(i -> system.out.println(i));     }      @override     protected void onpause() {         super.onpause();         printingnumbers.unsubscribe();     }  } 

range returns values @ once takes time on log visualize it. interval return values @ given time, way can test unsubscribe.

ps: think can combine range , interval emiits value limit @ given interval, not sure im learning rx


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -