1

I need to retrieve huge amounts of data from a database through a web service from an Android app. I have two different ways to do this, and I wanted some advice on it:

1. The first option is to create a .php file on the server side that managed any POST coming from the client (Android app). The server would then create a JSON response. Finally we would parse this response using a JSON parser in Android. This is also known as the REST scheme.

2. The second option is to create a SERVLET, execute it from the client (Android), have the servlet send the request to the database for us, and finally parse that data from Android. Obviously the servlet would be written so that it could easily interact with the database.

Points to note (so as to decide which option is better):

1. I won't be storing anything in the database from the client. That is, my Android app is read-only.

2. I will be reading from a huge database, so it is a priority here the performance of the Client-Server interaction, with a special mention for data parsing and for servlet vs php performance.

Any help would be greatly appreciated.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
Jose Lopez
  • 242
  • 4
  • 15

1 Answers1

2

Android has built-in support for parsing JSON data with the use of JSONObjects and JSONArrays, so it would be a lot easier to handle data in that form, rather than handling servlets. Its even possible to directly receive the web service response as a JSONObject or JSONArray.

In general, web services in Android should be of the RESTful type. That's how Google seems to prefer it. That's why there's built-in support for JSON, but not for SOA or Servlets.

References:

1. Reasons for not directly write Servlets for creating a REST API.

2. Servlet vs REST.

Community
  • 1
  • 1
Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • Is that the only benefit on using JSON? I mean, obviously Android will parse the JSON response better than any other, but what about the performance and the usability? Let's talk about WhatsApp (or Line, or Telegram): do you think those guys use servlets or php/json code? – Jose Lopez Apr 18 '15 at 16:20
  • In general, web services in Android should be of the RESTful type. That's how Google seems to prefer it. That's why there's built-in support for JSON, but not for SOA or Servlets. See edited answer. – Yash Sampat Apr 18 '15 at 16:24
  • Alright, but what if we converted the response to JSON from within the servlet before sending it to the client? – Jose Lopez Apr 18 '15 at 16:27
  • That's an option. You can do anything that simplifies your work while providing stable performance for both client and server. You need to define the balance for you and your project. See the added links :) – Yash Sampat Apr 18 '15 at 16:28
  • Can't upvote since requires 15 reputation, but I selected your answer as the accepted one. How do big companies developing for Android do in this specific subject? Do they go REST or Servlet? As of your answer I guess they follow the REST scheme. – Jose Lopez Apr 18 '15 at 16:32
  • Everything really depends on how data is being managed on the server-side. Its apparently even possible to create servlets that return data in JSON form. In any case, most apps receive data in JSON form as its very easy to parse for the client-side programmer. In some cases I have also seen apps that receive data in SOAP form. – Yash Sampat Apr 18 '15 at 16:38