我正在 android 中运行 Async(doInBackground) 任务。
我需要为任务填充进度条。所以我在 onPreExecute 中显示一个 progressDialog,
ProgressDialog.show的签名是Show(Context,Title,message)
但是这里的上下文是什么?
@Override
protected void onPreExecute()
{
progress = ProgressDialog.show(???, "Loading", "Please Wait");
}
最佳答案
为您的 AsyncTask 创建一个将上下文作为参数的构造函数。
public class async extends AsyncTask<String, Integer, String>{
private Context context;
public async(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
// Manipulate progress bar
}
然后用这个来执行
async mTask = new async(context).execute(params);
关于android - 异步任务中的上下文是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16566405/