I am trying to pull data from my webserver and add them to Local DB in background using a service.. Data is getting stored to Local DB without any issues but while this is happening the phone becomes slow (there is some dragging). Just wondering if I am doing things correctly in writing to DB or is there better and faster way to do it.
I am using AsyncHttpClient library to pull data from webserver.
final RequestParams requestParams = new RequestParams();
final String uploadWebsite = url_acc_details;
AsyncHttpClient client = new AsyncHttpClient();
client.post(uploadWebsite, requestParams, new JsonHttpResponseHandler()
{
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response)
{
try
{
success = response.getInt(TAG_SUCCESS);
if (success == Integer.parseInt(getResources().getString(R.string.successvalue)))
{
details = response.getJSONArray(TAG_DETAIL);
for (int i = 0; i < details.length(); i++)
{
JSONObject c = details.getJSONObject(i);
acc_iD = c.getString(TAG_ACC_ID);
acc_nAme = c.getString(TAG_ACC_NAME);
acc_Image = c.getString(TAG_ACC_IMAGE);
acc_active = c.getString(TAG_ACC_ACTIVE);
acc_priority = c.getString(TAG_ACC_PRIORITY);
acc_creator = c.getString(TAG_ACC_CREATOR);
dblocal.setAccDetails(Integer.valueOf(acc_iD), acc_nAme, acc_Image, acc_active, acc_priority, acc_creator);
}
}
}
catch (JSONException e)
{
e.printStackTrace();
}
stopSelf();
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse)
{
super.onFailure(statusCode, headers, throwable, errorResponse);
stopSelf();
}
});
Similarly I am starting three services running in bankground at the same time with same above logic but for getting different details.
It would be great if somebody could let me know the way to do the above process faster and better?