How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?

前端 未结 17 2195
鱼传尺愫
鱼传尺愫 2020-11-21 04:50

I have this two classes. My main Activity and the one that extends the AsyncTask, Now in my main Activity I need to get the result from the OnPostExecute(

17条回答
  •  悲哀的现实
    2020-11-21 05:16

    Create a static member in your Activity class. Then assign the value during the onPostExecute

    For example, if the result of your AsyncTask is a String, create a public static string in your Activity

    public static String dataFromAsyncTask;

    Then, in the onPostExecute of the AsyncTask, simply make a static call to your main class and set the value.

    MainActivity.dataFromAsyncTask = "result blah";

提交回复
热议问题