Android : Android Asynctask check status(finished)

on Friday, August 29, 2014


i 'm working asynctask class. i try parse json and show it.everythink is ok at the monment.but i have one problem.i want to check status my Asynctask class.i mean i want to check when finished Asyncttask this is a my code



private class LoadItemFromServer extends AsyncTask<String, Void, String> {

ProgressDialog pDialog;

@Override
protected void onPreExecute() {
super.onPreExecute();

pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
}

@Override
protected String doInBackground(String... params) {

try {


JsonResult = FlashScreen
.execute(
"***************",
FlashScreen.CreateJson(
"GetCategoryHierharchy", "eng"));




} catch (Exception e) {

}

return null;
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);

if (pDialog != null) {
pDialog.dismiss();

pDialog = null;
}

Log.e("serverrrr", JsonResult);
try {
ParseJsonFromServer(JsonResult);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}



public void ParseJsonFromServer(String server) throws JSONException {
JSONArray jsonArray = null;
JSONObject mainJson = new JSONObject(server);
jsonArray = mainJson.getJSONArray("result");

for (int i = 0; i < jsonArray.length(); i++) {
JSONObject data = jsonArray.getJSONObject(i).getJSONObject("data");

Azercell_PagerTitleStrip_items objItem = new Azercell_PagerTitleStrip_items();

objItem.setTitle(data.getString("title"));
Log.e("titlesss", data.getString("title"));
arrayOfList.add(objItem);
}

}


my problem is this part code:



loaditem = new LoadItemFromServer();

loaditem.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
try {
if (loaditem.getStatus() == AsyncTask.Status.FINISHED) {
for (int i = 0; i < arrayOfList.size(); i++) {
page = inflater.inflate(R.layout.azercell_category_pages, null);
// setAdapterToListview(page);
titles.add(arrayOfList.get(i).getTitle());
pages.add(page);
}
} else {
Log.e("asynctask status", "not finished");
}
} catch (Exception e) {
}


at the moment my arrayOfList array's size is 0,but i loged ParseJsonFromServer and this array's size is not 0. i can not wait,when asynctas is finished how i can solve my problem? if anyone knows solution please help me


0 comments:

Post a Comment