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.
Android has built-in support for parsing JSON data with the use of JSONObject
s and JSONArray
s, 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.