Utilizing Retrofit with RxJava to enhance mobile app performance
Retrofit + RxJava
1
1 Introductory Talk about RxJava & Retrofit including current trend & scenario.
Retrofit + RxJava
2
Understanding the functioning of RxJava
Retrofit + RxJava
3
3 Understanding RxJava
Retrofit + RxJava
4
Understanding the use of Observable.just()
import import import public
java.util.Arrays; java.util.List; rx.Observable; class RxJavaExample { public static void main(String[] args) { List list = Arrays.asList("Android", "Ubuntu", "Mac OS"); Observable> listObservable = Observable.just(list); listObservable.subscribe(new Observer>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(List list) { System.out.println(list); } }); } }
Retrofit + RxJava
5
4 Retrofit Model to make it work with RxJava
Retrofit + RxJava
6
static T createRetrofitService(final Class class, final String endPoint) { final RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(endPoint) .build(); T service = restAdapter.create(clazz); return service; }
The Github REST API gives you back the accompanying JSON. You can attempt it yourself! {
}
"login": "LinkedIn", "blog": "http://engineering.linkedin.com", "public_repos": 73, //...truncated JSON
Retrofit + RxJava
7
public class Github { private String login; private String blog; private int public_repos; public String getLogin() { return login; } public String getBlog() { return blog; } public int getPublicRepos() { return public_repos; } }
Retrofit + RxJava
8
5 Comparing Retrofit with Google Volley
Retrofit + RxJava
9
Retrofit + RxJava
10
6 CONCLUSION
Retrofit + RxJava
11