android - Why is my timer Observable never called? -



android - Why is my timer Observable never called? -

on android, have written observable should called 1 time after 2000 msec, never called.

observable.timer(2000, timeunit.milliseconds) // wait 2000 msec .subscribeon(schedulers.newthread()).observeon(androidschedulers.mainthread()) .flatmap(new func1<long, observable<?>>() { @override public observable<?> call(long along) { continueplayback(); // line never called homecoming null; } });

i want observable wait off main thread, phone call "continueplayback()" on main thread. context help allowed me place subscribeon/observeon between timer , flatmap. correct? happening here , did wrong?

what happens observable after call. remain live or need explicitly tear downwards somehow, e.g. phone call oncompleted()?

most obsersables passive default , emit items if subscribed to. in code illustration you're not subscribing observable. hence never starts emitting items or in case items after 2000 milliseconds.

flatmap operator help manipulate stream of info doesn't subscribe stream of observables.

instead of using flatmap should replace phone call subscribe.

observable.timer(2000, timeunit.milliseconds) .subscribeon(schedulers.newthread()) .observeon(androidschedulers.mainthread()) .subscribe(new action1<long>() { @override public void call(long along) { continueplayback(); } });

i used action instead of observer in subscribe since don't believe you'll need handle onerror in particular case.

the observable timer finish after emitting it's item.

keep in mind if you're using observables within fragment or activity should create sure unsubscribe observables eliminate chances of memory leaks.

here's quick link hot , cold observables in rxjava

android rx-java

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -