Skip to content Skip to sidebar Skip to footer

Asynctask And Json, Onsuccess Doesn't Return Anything

I'm here with another question. I post you the code from my AsyncTask function to get values from a JSONObject (webservice). My problem is that I have a List and I fill this list w

Solution 1:

if you are using loopj android-async-http then no need to use AsyncTask for getting data from server doInBackground and updating UI in onPostExecute because onSuccess method always execute on UI Thread after background computation. just do it without AsyncTask as :

AsyncHttpClient client = newAsyncHttpClient();
 client.get("Pass Url Here", null, newJsonHttpResponseHandler() {
     @OverridepublicvoidonSuccess(JSONObject data) {
          // update your ListView here
      }
    @OverridepublicvoidonFailure(Throwable arg0, JSONObject arg1) {
        // TODO Auto-generated method stubsuper.onFailure(arg0, arg1);

    }
  });

Solution 2:

onPostExecuted is called when the doInBackground runs out its execution. If the get method of AsyncHttpClient is not a blocking method, onPostExecuted is called before onSuccess parses the result

Solution 3:

onPostExecuted is called before onSuccess parses the result, So try display something in your loop or debug that code.

    Log.e("Test", item.getString("id"));//inside for Loop

And Also use this before your for loop

listCategories = new List<Category>();

Hopes it help.

Post a Comment for "Asynctask And Json, Onsuccess Doesn't Return Anything"