I am new to android development and now i am developing an e commerce application in android for online shopping.So far in this project i have created a shopping cart to hold articles selected by user. But every thing i have done works statically.
Now i have to communicate with the server to get updates about products and discounts.
I know how to consume webservices using json.
1.I am confused about that everytime i start my application i should communicate with server using webservice ?? or should i store the data in application when application is executed for the first time on device.
2.And what approach to store data should i follow
I should store it in device cache or
I should store it in applications sqlite db
Edit :
get data from webservice
try {
Log.v("inside webservice call ", "1");
HttpPost request = new HttpPost(url);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
// Build JSON string
Log.v("inside webservice call ", "2");
JSONStringer JsonString = new JSONStringer().object().key("prodid")
.value("4057339").endObject();
StringEntity entity = new StringEntity(JsonString.toString());
request.setEntity(entity);
Log.v("data", JsonString.toString());
Log.v("inside webservice call ", "2");
DefaultHttpClient httpClient1 = new DefaultHttpClient();
HttpResponse response = httpClient1.execute(request);
Log.v("inside webservice call ", "3");
Log.v("response code", response.getStatusLine().getStatusCode()
+ "");
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int) responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
Log.v("inside webservice call ", "4");
results = new JSONObject(new String(buffer));
// Populate text fields
String message = results.getString("message");
String isvalid = results.getString("isvalid");
Log.v("tag", message + isvalid);
Log.v("inside webservice call ", "5");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
I do this to get data from server
but unable to put this data in sqlite db please guide me
This totally depends on your requirement of the project,means if the data is going to be updated frequently then you should load it everytime,you can also load data periodically and if possible make one extra service from server that notify you for updates and you just need to check that only everytime.
For the images and other media you can store them to SDCard once and next time just check if they alreay exist then don’t go for loading,this can save your process time.
To store the data as you are loading many specific and formatted and categoriesed information then sqlite db would be more help ful to store and retrieve data.