Skip to content

Instantly share code, notes, and snippets.

@BalakrishnanPT
Created October 18, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BalakrishnanPT/bf231f3841eff4d0976e5caf62a01cd3 to your computer and use it in GitHub Desktop.
Save BalakrishnanPT/bf231f3841eff4d0976e5caf62a01cd3 to your computer and use it in GitHub Desktop.
// Calling function, This is in Activity or Viewmodel
public void blockingGetExample() {
BoredActivitiesAPI sampleAPI = getRetrofitInstance.create(BoredActivitiesAPI.class);
// Eventhough RxJava call is happening in diffrent thread, Result of the RxJava will be strored in
// `s` and nexr line is executed.
String s = sampleAPI.getSingleResponse()
.onErrorReturn(new Function<Throwable, BoredActivities>() {
@Override
public BoredActivities apply(Throwable throwable) throws Exception {
BoredActivities boredActivities = new BoredActivities();
boredActivities.setLink("");
return boredActivities;
}
})
.map(new Function<BoredActivities, String>() {
@Override
public String apply(BoredActivities boredActivities) throws Exception {
return boredActivities.getLink();
}
})
.subscribeOn(Schedulers.io()).blockingGet();
Log.d("Sample", "blockingGetExample: "+s);
}
// Retrofit Method, interface, name - BoredActivitiesAPI.java
@GET("activity")
Single<BoredActivities> getSingleResponse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment