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 = new AsyncHttpClient();
 client.get("Pass Url Here", null, new JsonHttpResponseHandler() {
     @Override
     public void onSuccess(JSONObject data) {
          // update your ListView here
      }
    @Override
    public void onFailure(Throwable arg0, JSONObject arg1) {
        // TODO Auto-generated method stub

         super.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"