我想在异步任务onPreExecute()
中显示进度条。但我无法通过context
。有人可以帮忙吗?在Android中的异步任务中显示进度条
public class myClass extends AsyncTask<Void,Void,Void>{
Context ctx;
ProgressDialog d;
String s;
public myClass (String S, Context con) {
this.ctx = con;
this.s = S;
}
@Override
protected void onPreExecute() {
d = new ProgressDialog(this.ctx);
d.setMessage("Please wait...");
d.setIndeterminate(true);
d.show();
}
从主要活动作为调用
new myClass(MainActivity.this);
myClassObj.execute(s);
你可以使用getApplicationContext()方法为此 –
使用构造函数 –
@RahulKhurana我应该在哪里使用它? – Amar