Network programming in Android. Using restful Api in Android.

useful blog :
 https://www.vogella.com/tutorials/AndroidNetworking/article.html




Before you begin with networking you must know about java input & output  streams.

https://www.youtube.com/watch?v=kD_HqZP8MLY
https://www.tutorialspoint.com/what-is-a-stream-and-what-are-the-types-of-streams-and-classes-in-java




While using a localhost , always use the ip address "10.0.2.2" as the domain name in the android java code.










--------------------------------------------------------------------------------------------------



All networking should be done in the background , on the worker thread.


We can use either the Threads and runnables form java classes or use the following android specific things liek Intentservice , AsynctaskLoader etc depending on our situation.






-----------------------------------------------------------------------------------



There are 3 ways we can connect to a network in android.


1] Java's HttpUrlConnection


2] Android specific implementations of existing API. 


Eg - Android specific HttpUrlConnection (Internally uses OkHttp) . In this all the methods are same , just the internal implementation differs from Java's own HttpUrlconnection class.


3] External libraries - Retrofit , picaso  etc


In most cases we use the GSON class to parse the Json data into Pojo or Plain old java objects.

























---------------------------------------------------------------------------------




















































Comments

Popular posts from this blog

React Js + React-Redux (part-2)

React Js + CSS Styling + React Router (part-1)

ViteJS (Module Bundlers, Build Tools)