Android Event Bus Alternative -


context: in previous android application have developed, used event bus (otto square) handle async task results (for example: result of server request posted on bus , somewhere in application intercept response). although did job, in article i've read mentioned using such bus rather bad idea it's considered antipattern.

why so? alternatives using event bus when dealing results of async operations? know that, of time, there no standard way handle things, there "a more canonical" method?

use rxjava , retrofit asynchronous network calls. rxjava provide out of box support retrofit.

return observable retrofit interface.

@get("/posts/{id}") public observable<post> getdata(@path("id") int postid); 

use in activity class -

retrofitbuilderclass.getapi()  .getdata()  .subscribeon(schedulers.newthread())  .observeon(androidschedulers.mainthread())  .subscribe(new observer < list < data >> () {   @override   public void oncompleted() {    }    @override   public void onerror(throwable e) {    }    @override   public void onnext(list < data > data) {   // display data   }  }); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -