Created
October 18, 2019 12:16
-
-
Save BalakrishnanPT/ea6281f15f5dc7882c2e74b3ec46b848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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