Can I pass different types of parameters to an AsyncTask in Android?

后端 未结 2 957
忘了有多久
忘了有多久 2021-02-05 04:52

I want to implement a generic, thread save class which takes the RessourceId of an ImageView and the Url (http) where the desired image file is stored. It\'ll download the image

2条回答
  •  春和景丽
    2021-02-05 05:26

    You can add setter methods to your AsyncTask implementation, or even define your own constructor to pass additional parameters.

    Optionally, if your AsyncTask implementation is an inner class of an activity you can access all the instance variables of your activity. I prefer the above option myself, as it clearly indicates which data the task requires.

提交回复
热议问题