When do you use map vs flatMap in RxJava?

When do you use map vs flatMap in RxJava? Say, for example, we want to map Files containing JSON into Strings that contain the JSON– Using map, we have to deal with the Exception somehow. But how?: Observable.from(jsonFile).map(new Func1<File, String>() { @Override public String call(File file) { try { return new Gson().toJson(new FileReader(file), Object.class); } … Read more

Difference between CompletableFuture, Future and RxJava’s Observable

I would like to know the difference between CompletableFuture,Future and Observable RxJava. What I know is all are asynchronous but Future.get() blocks the thread CompletableFuture gives the callback methods RxJava Observable — similar to CompletableFuture with other benefits(not sure) For example: if client needs to make multiple service calls and when we use Futures (Java) … Read more

Use cases for RxJava schedulers

In RxJava there are 5 different schedulers to choose from: immediate(): Creates and returns a Scheduler that executes work immediately on the current thread. trampoline(): Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes. newThread(): Creates and returns a Scheduler that creates a new … Read more

When should one use RxJava Observable and when simple Callback on Android?

I’m working on networking for my app. So I decided to try out Square’s Retrofit. I see that they support simple Callback @GET(“/user/{id}/photo”) void getUserPhoto(@Path(“id”) int id, Callback<Photo> cb); and RxJava’s Observable @GET(“/user/{id}/photo”) Observable<Photo> getUserPhoto(@Path(“id”) int id); Both look pretty similar at first glance, but when it gets to implementation it gets interesting… While with … Read more