在doInBackground AsyncTask Android中传递更多值 [英] Pass more values in doInBackground AsyncTask Android
本文介绍了在doInBackground AsyncTask Android中传递更多值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 doInBackground
我的 AsyncTask
看起来像这样.
private class DownloadFile extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... sUrl) {
{
}
}
是否有可能以其他方式在受保护的String DoInBackground
Is it possible somehow to pass more values on my protected String DoInBackground
例如:受保护的字符串doInBackground(String ... sUrl,String ... otherUrl,Context context)
以及之后如何执行
AsyncTask
? new DownloadFile.execute(",",this)
或其他内容?
And how to execute
the AsyncTask
after? new DownloadFile.execute("","",this)
or something?
推荐答案
String... sUrl
三个连续的点意味着一个字符串以上.点是可变参数
the three consecutive dots meaning more then one String. The dots are varargs
以及如何传递上下文?
And how to pass the Context?
您可以强制其添加以Context作为参数的构造函数:
you can force it adding a constructor that takes the Context as parameter:
private Context mContext;
public void setContext(Context context){
if (context == null) {
throw new IllegalArgumentException("Context can't be null");
}
mContext = context;
}
这篇关于在doInBackground AsyncTask Android中传递更多值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文