[Solved] passing string data from onPostExecute method of AsyncTask to other activity


In my opinion two options are available on the table!

1.Create your AsyncTask class as an inner class inside your Activity class, and then you can gain access for all super class properties.

public class MyActivity extends Activity {

    int property1;
    void method1() {

    }

    private class MyTask extents AsyncTask<Void, Void, Void> {

        @Override
        protected void onPostExecute(Void param)
            method1(...); // <-- this is method of the enclosing class
        }
    }
}

2.Define a public interface for your AsyncTask class and call its listener in the onPostExecute

public class MyTask extends AsyncTask<Void, Void, Void> {

    OnTaskFinishedListener mListener;

    @Override
    protected void onPostExecute(Void param)
        if(mListener != null){
            mListenr.onFinished(...); // <-- call your callback
        } 
    }

    public void setOnTaskFinishedListener(OnTaskFinishedListener listener) {
        mListener = listener;
    }

    public interface OnTaskFinishedListener {
        public void onFinished(...);
    }

}

solved passing string data from onPostExecute method of AsyncTask to other activity