Return value from AsyncTask class onPostExecute method

I guess you are trying to read class A variable before it is being set..
Try to do it using callbacks..in the callback function pass the values and refresh your spinners..

You can create interface, pass it to AsyncTask (in constructor), and then call method in onPostExecute

For example:

Your interface:

public interface OnTaskCompleted{
    void onTaskCompleted(values);
}

Your Activity:

public YourActivity implements OnTaskCompleted{
    //your Activity
    YourTask  task = new YourTask(this); // here is the initalization code for your asyncTask
}

And your AsyncTask:

public YourTask extends AsyncTask<Object,Object,Object>{ //change Object to required type
    private OnTaskCompleted listener;

    public YourTask(OnTaskCompleted listener){
        this.listener=listener;
    }

    //required methods

    protected void onPostExecute(Object o){
        //your stuff
        listener.onTaskCompleted(values);
    }
}

Leave a Comment