android - Implement RxJava with Sync Adapters -


i'm trying use rxjava through rxandroid , others librarys rxlifecycle update activity after fetching data syncadapter. know how execute network call throug service when call activity. example:

observable<string> fetchfromgoogle = observable.create(new observable.onsubscribe<string>() {     @override     public void call(subscriber<? super string> subscriber) {         try {             string data = fetchdata("http://www.google.com");             subscriber.onnext(data); // emit contents of url             subscriber.oncompleted(); // nothing more emit         }catch(exception e){             subscriber.onerror(e); // in case there network errors         }     } });  fetchfromgoogle .subscribeon(schedulers.newthread()) // create new thread .observeon(androidschedulers.mainthread()) // use ui thread .subscribe(new action1<string>() {     @override     public void call(string s) {         view.settext(view.gettext() + "\n" + s); // change view     } }); 

the problem when using syncadapter syncmanager responsable start service fetch data. therefore don't know how create observable suscribes on thread hasn't been started , observes on ui.

i thinking in creating singleton subject activity can suscribe on, , in syncadapter create observable emitis event when done (after suscribing singleton subject).

what better/right solution?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -