SlideShare a Scribd company logo
Awesome
Android Network Library
Old Times - Connect HTTP Protocol
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
HttpClient client = new DefaultHttpClient(httpParameters);
HttpGet post = new HttpGet(urlString);
HttpResponse responseGET;
try {
responseGET = client.execute(post);
HttpEntity resEntity = responseGET.getEntity();
if (resEntity != null) {
String resEntityString = EntityUtils.toString(resEntity);
return resEntityString;
}
} catch (Exception e) {
e.printStackTrace();
}
Old Times - JSON Converter
JSONObject jsonObject = new JSONObject(data);
String questionId = jsonObject.getString(PARAMETER1);
String questionName = jsonObject.getString(PARAMETER2);
String questionOther = jsonObject.getString(PARAMETER3);
JSONArray jarr = new JSONArray(jsonObject.getString(JSON_CONTENT))
ArrayList<ChoiceModel> choiceItem = new ArrayList<ChoiceItemModel>();
for (int i = 0; i < jarr.length(); i++){
JSONObject jo = jarr.getJSONObject(i);
ChoiceItemModel item = new ChoiceItemModel();
item.setQuestionId(questionId);
item.setChoiceName(jo.getString(JSON_CHOICE));
item.setChoiceOther(jo.getInt(JSON_CHOICE_OTHER));
surveyItem.add(item);
}
“Don’t reinvent the wheel”
— Naïve Man
Butterknife
Retrofit (Network)
Picasso (Image download and cache handler)
RoboSpice (Asynchronous lib)
Lombok
RetroLambda
Libs:
Never again:
HttpConnection
Retrofit
➢ Model (POJO)
➢ Interface Service
➢ Adapter / Call
➢ Converter such as GSON
Retrofit
public class Question {
private String question;
private String url;
public String getQuestion() {
return question;
}
public String getUrl() {
return url;
}
}
Retrofit (Model POJO)
public interface RetrofitRequestService {
@GET("/questions")
Call<List<Question>> ques();
}
Retrofit (Service Interface)
Retrofit mRestAdapter = new Retrofit
.Builder()
.baseUrl("http://private-9adb36-crashback.apiary-mock.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
service = mRestAdapter.create(RetrofitRequestService.class);
Retrofit (Adapter / Call)
Call<List<Question>> call = service.ques();
//call on another thread not in main thread
call.enqueue(new Callback<List<Question>>() {
@Override
public void onResponse(Call<List<Question>> call, Response<List<Question>> response) {
System.out.println("Question = " + response.body().get(0).getQuestion());
System.out.println("url = " + response.body().get(0).getUrl());
}
@Override
public void onFailure(Call<List<Question>> call, Throwable t) {
}
});
Retrofit (Adapter / Call)
“Simple, it is wrapped”
— Naïve Man
https://github.com/faren/Retrofit
https://id.linkedin.com/in/farenfaren
http://slideshare.net/farenfa
attr
faren.faren@gmail.com
Dev Manager Tiket.com
Ping me

More Related Content

PDF
Facilite a vida com guava
PDF
Liquid Stream Processing Across Web Browsers and Web Servers
PPTX
Android getting started
PDF
Android webservices
PDF
Fault tolerant microservices - LJC Skills Matter 4thNov2014
PDF
LJC Conference 2014 Cassandra for Java Developers
PDF
Elasticsearch und die Java-Welt
PDF
Leap Ahead with Redis 6.2
Facilite a vida com guava
Liquid Stream Processing Across Web Browsers and Web Servers
Android getting started
Android webservices
Fault tolerant microservices - LJC Skills Matter 4thNov2014
LJC Conference 2014 Cassandra for Java Developers
Elasticsearch und die Java-Welt
Leap Ahead with Redis 6.2

What's hot (20)

PDF
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
PDF
High Performance Python Microservice Communication
PDF
VBA API for scriptDB primer
PPT
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
PDF
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
PDF
Node.js Stream API
PDF
Elk stack @inbot
PDF
Using script db as a deaddrop to pass data between GAS, JS and Excel
PPTX
Building Your First Data Science Applicatino in MongoDB
PDF
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
PPTX
Diagnostics and Debugging
ODP
Testing Asynchronous Algorithms Exhaustively on node.js
PPTX
Retrofit Technology Overview by Cumulations Technologies
ODT
Logic Equations Resolver J Script
PDF
Monitoring microservices with Prometheus
PDF
Redis
PPTX
Mastering advanced concepts in Silverlight
PDF
"The little big project. From zero to hero in two weeks with 3 front-end engi...
PDF
JSONSchema with golang
KEY
Gevent what's the point
Infinum Android Talks #18 - How to cache like a boss by Željko Plesac
High Performance Python Microservice Communication
VBA API for scriptDB primer
Realtime Analytics Using MongoDB, Python, Gevent, and ZeroMQ
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Node.js Stream API
Elk stack @inbot
Using script db as a deaddrop to pass data between GAS, JS and Excel
Building Your First Data Science Applicatino in MongoDB
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
Diagnostics and Debugging
Testing Asynchronous Algorithms Exhaustively on node.js
Retrofit Technology Overview by Cumulations Technologies
Logic Equations Resolver J Script
Monitoring microservices with Prometheus
Redis
Mastering advanced concepts in Silverlight
"The little big project. From zero to hero in two weeks with 3 front-end engi...
JSONSchema with golang
Gevent what's the point
Ad

Similar to Android Network library (6)

PPT
Android httpclient
PPTX
Performance #4 network
PDF
Android Performance #4: Network
PDF
Android http library
PDF
Connecting to Web Services on Android
PDF
Android and the Seven Dwarfs from Devox'15
Android httpclient
Performance #4 network
Android Performance #4: Network
Android http library
Connecting to Web Services on Android
Android and the Seven Dwarfs from Devox'15
Ad

More from Faren faren (6)

PPTX
Design sprint slideshare
PPTX
Microservices architecture
PPTX
Functional Reactive Programming (FRP)
PPTX
Java Play RESTful ebean
PPTX
Java Play Restful JPA
PPTX
Product Design Sprint
Design sprint slideshare
Microservices architecture
Functional Reactive Programming (FRP)
Java Play RESTful ebean
Java Play Restful JPA
Product Design Sprint

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
assetexplorer- product-overview - presentation
PPTX
history of c programming in notes for students .pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Introduction to Artificial Intelligence
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Transform Your Business with a Software ERP System
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
medical staffing services at VALiNTRY
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 2 - PM Management and IT Context
Which alternative to Crystal Reports is best for small or large businesses.pdf
Understanding Forklifts - TECH EHS Solution
PTS Company Brochure 2025 (1).pdf.......
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
assetexplorer- product-overview - presentation
history of c programming in notes for students .pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Operating system designcfffgfgggggggvggggggggg
Introduction to Artificial Intelligence
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Transform Your Business with a Software ERP System
2025 Textile ERP Trends: SAP, Odoo & Oracle
medical staffing services at VALiNTRY
Reimagine Home Health with the Power of Agentic AI​
Digital Systems & Binary Numbers (comprehensive )
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 2 - PM Management and IT Context

Android Network library

  • 2. Old Times - Connect HTTP Protocol HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 10000); HttpConnectionParams.setSoTimeout(httpParameters, 5000); HttpClient client = new DefaultHttpClient(httpParameters); HttpGet post = new HttpGet(urlString); HttpResponse responseGET; try { responseGET = client.execute(post); HttpEntity resEntity = responseGET.getEntity(); if (resEntity != null) { String resEntityString = EntityUtils.toString(resEntity); return resEntityString; } } catch (Exception e) { e.printStackTrace(); }
  • 3. Old Times - JSON Converter JSONObject jsonObject = new JSONObject(data); String questionId = jsonObject.getString(PARAMETER1); String questionName = jsonObject.getString(PARAMETER2); String questionOther = jsonObject.getString(PARAMETER3); JSONArray jarr = new JSONArray(jsonObject.getString(JSON_CONTENT)) ArrayList<ChoiceModel> choiceItem = new ArrayList<ChoiceItemModel>(); for (int i = 0; i < jarr.length(); i++){ JSONObject jo = jarr.getJSONObject(i); ChoiceItemModel item = new ChoiceItemModel(); item.setQuestionId(questionId); item.setChoiceName(jo.getString(JSON_CHOICE)); item.setChoiceOther(jo.getInt(JSON_CHOICE_OTHER)); surveyItem.add(item); }
  • 4. “Don’t reinvent the wheel” — Naïve Man
  • 5. Butterknife Retrofit (Network) Picasso (Image download and cache handler) RoboSpice (Asynchronous lib) Lombok RetroLambda Libs:
  • 7. ➢ Model (POJO) ➢ Interface Service ➢ Adapter / Call ➢ Converter such as GSON Retrofit
  • 8. public class Question { private String question; private String url; public String getQuestion() { return question; } public String getUrl() { return url; } } Retrofit (Model POJO)
  • 9. public interface RetrofitRequestService { @GET("/questions") Call<List<Question>> ques(); } Retrofit (Service Interface)
  • 10. Retrofit mRestAdapter = new Retrofit .Builder() .baseUrl("http://private-9adb36-crashback.apiary-mock.com/") .addConverterFactory(GsonConverterFactory.create()) .build(); service = mRestAdapter.create(RetrofitRequestService.class); Retrofit (Adapter / Call)
  • 11. Call<List<Question>> call = service.ques(); //call on another thread not in main thread call.enqueue(new Callback<List<Question>>() { @Override public void onResponse(Call<List<Question>> call, Response<List<Question>> response) { System.out.println("Question = " + response.body().get(0).getQuestion()); System.out.println("url = " + response.body().get(0).getUrl()); } @Override public void onFailure(Call<List<Question>> call, Throwable t) { } }); Retrofit (Adapter / Call)
  • 12. “Simple, it is wrapped” — Naïve Man