I wrote a asynctask to process json,The json result is very long (need 40 - 70 seconds to process on 2G).The asynctask publishProgress(""); function execute only after fetching and processing the json ( just before postexecute() ). How can i update each second.
class LoadAllProducts extends AsyncTask<String, String, String> {
int per=100;
@Override
protected void onPreExecute()
{
super.onPreExecute();
clear();
pDialog = new ProgressDialog(Load.this);
pDialog.setMessage("Loading ... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url, "POST", params);
publishProgress("");
if(json!=null) {
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1)
{
products = json.getJSONArray(TAG_PRODUCTS);
for (int i = 0; i < products.length(); i++)
{
JSONObject c = products.getJSONObject(i);
////////////////////////////////// Other codes
}
} else {}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(String file_url)
{
pDialog.dismiss(); load(0);
}
@Override
protected void onProgressUpdate(String... text)
{
per=per-1;
pDialog.setMessage("Loading Questions... Please wait..."+per);
}
}
I refered : Android, java - Unable to update variable from asynctask