Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data from server to android app: REST vs Sockets [closed]

I'am writing an android app that needs some data from the server. I am also writing the server side in Java.

  • What is the best way to pass data from the server to the android device: with REST or Sockets (like Kryonet)?
  • In what format: XML/JSON (for REST) or plain Java objects?

Thanks in advance.

like image 521
user1786646 Avatar asked Sep 23 '14 22:09

user1786646


2 Answers

"Best" is very subjective, I think a very good way to communicate with a RESTful api is via Square's Retrofit library, which can be found here: http://square.github.io/retrofit/

There is also Volley from Google, http://developer.android.com/training/volley/index.html

like image 187
nPn Avatar answered Nov 14 '22 23:11

nPn


Agree with nPn, "Best" depends on lot of app and user considerations. That said,

  • REST is preferred as it is most widely used and you have access to stable and optimized client libraries. Most of the these libraries support all kinds of use-cases and customizations. Web Sockets are well suited for real time or live content. If you have a different use-case , REST is strongly recommended.

  • With Android, JSON is well supported. There is a core JSON API included with Android that you can use without any client libraries. XML can be helpful if you plan to expose your APIs for public consumption (some platforms eg: JAVA, windows have strong XML legacy).

REST + JSON seems to be most commonly used combination in recent times, and lot of client libraries usually enable this use-case.

like image 20
ashoke Avatar answered Nov 15 '22 00:11

ashoke