android - RxJava Thread.sleep in another thread -
how use rxjava
update ui
every 1 second in android? i'm trying this:
(int = 0; <10 ; i++) { //test rx.observable.just(getsleep()) .subscribeon(schedulers.newthread()) .observeon(androidschedulers.mainthread()) .subscribe(v->updatetime());//update textview } private <t> int getsleep() { try { thread.sleep(1000); } catch (interruptedexception e) { e.printstacktrace(); } return 0; }
but thread.sleep() doing in ui thread. wrong?
observable.interval(1, timeunit.seconds) //emits item every second .observeon(androidschedulers.mainthread()) //switches thread computation (interval's default) ui .subscribe(i -> updateui()); //update textview
Comments
Post a Comment