How to make activity UI changes from an Android AsyncTask?

后端 未结 3 976
深忆病人
深忆病人 2021-01-17 20:23

In a scenario where I have a UI that will be updated from a separate thread (using AsyncTask), I can define the AsyncTask as an inner class of the activity, but this has two

3条回答
  •  孤街浪徒
    2021-01-17 20:53

    Quite a few examples I have seen just pass a Context into the constructor of the AsyncTask.

    public class BackgroundStuff extends AsyncTask {
        ...
        Context mContext;
        ...
        BackgroundStuff(Context context){
            super();
            this.mContext = context;
        }
        ...
    }
    

    I would be interested to hear if anyone else uses any other approaches.

提交回复
热议问题