In your situation, I would choose JSON over XML for the whole reason indicated in the following post: http://ajaxian.com/archives/json-vs-xml-the-debate
In addition, the android has a built-in JSON Array, so you do not need to perform additional code transfer.
return new JSONArray("my json string goes here...");
Since we are talking about a mobile device, I will always generate changes in your php script, and not have full synchronization, since it will be much smaller in size than full synchronization. However, you will need to provide the user with the ability to complete a full re-synchronization, if applicable to your application. I would use a SQLite database to store data and update only the changes.
To make the stream smaller, you can gzip compress your output from php since it can be read by an Android device from the beginning. In my application, I compress 500 kB to ~ 110 kB before transfer, which greatly saves on performance. Here is a partial example of how to read a stream:
InputStream in = null; HttpURLConnection httpConn = null; // you will have to write your on code for this bit. if (httpConn.getContentEncoding() != null) { String contentEncoding = httpConn.getContentEncoding().toString(); if (contentEncoding.contains("gzip")) { in = new GZIPInputStream(httpConn.getInputStream()); } } else { in = httpConn.getInputStream(); }
I hope this all makes sense, it was a long day of programming :)
Stu
source share