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

后端 未结 2 953
忘了有多久
忘了有多久 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:06

    You can pass params as objects

    new MyTask().execute(url, str, context);
    
    public class MyTask extends AsyncTask {
        @Override
        protected Void doInBackground(Object... params) {
                Url url = (Url) params[0];
                String str = (String) params[1];
                Context ctx = (Context) params[2];
    
                return null;
        }
    }
    

提交回复
热议问题