Hai am trying to send list elements to the another activity through asynctask but i cant get the proper result can you please help me..
this is my asnctask :
public class AsyncClass extends AsyncTask {
Context ct;
ArrayList<GetterSetterClass> listshows;
private String TAG = "AsynClass";
GetterSetterClass gettersettercls;
MainActivity mainActivity;
// Communication between asynclass and mainactivity
public AsyncClass(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
public interface ListenerClass {
public void callbackMyActivity();
}
// Get the Url response from this method
public String queryRESTurl(String urlString) {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpPost httpGet = new HttpPost(urlString);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (BuildConfig.DEBUG)
Log.i("QueryResult", builder.toString());
return builder.toString();
}
public JSONObject convertStringtoJsonObject(String result) {
JSONObject jArray = null;
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
}
return jArray;
}
@Override
protected String doInBackground(String... params) {
if (BuildConfig.DEBUG)
Log.i("EnterDoinbackground", "EnterDoinbackground");
try {
if (BuildConfig.DEBUG)
Log.i("ShowsUrl", params[0]);
String results = queryRESTurl(params[0]);
if (results != null) {
JSONObject json = convertStringtoJsonObject(results);
try {
listshows = new ArrayList<GetterSetterClass>();
JSONObject result = json
.getJSONObject(MainActivity.Rootnode);
Log.d("Get the string results", "" + result);
JSONArray jarray = result.getJSONArray(MainActivity.shows);
int jasonarrayLength = jarray.length();
for (int i = 0; i < jasonarrayLength; i++) {
JSONObject jsonkey = jarray.getJSONObject(i);
gettersettercls = new GetterSetterClass(
jsonkey.getString(MainActivity.DATE_CREATED),
jsonkey.getString(MainActivity.SHOW_NAME),
jsonkey.getString(MainActivity.PLAY_NAME),
jsonkey.getString(MainActivity.SHOW_COVER),
jsonkey.getInt(MainActivity.ASSET_COUNT),
jsonkey.getInt(MainActivity.SHOW_ID),
jsonkey.getString(MainActivity.LINK_MD5),
jsonkey.getString(MainActivity.DESCRIPTION));
listshows.add(gettersettercls);
/*
* Log.i("list elements", "List elements displayed :\n"
* + listshows);
*/
}
} catch (Exception e) {
Log.d(TAG, "Exception thrown :" + e);
}
} else {
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.i("Listitems", "" + listshows.size());
Message msg = Message.obtain();
msg.obj = listshows;
Handler handler = new Handler();
handler.sendMessage(msg);
if (!mainActivity.isFinishing()) {
mainActivity.callbackMyActivity();
}
}
}