我有这个代码片段:
public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean>
{
private final ProgressDialog dialog = new ProgressDialog(ctx);
protected void onPreExecute();
protected Boolean doInBackground(final String... args);
protected void onPostExecute(final Boolean success);
}
Run Code Online (Sandbox Code Playgroud)
我执行这个线程为
new ExportDatabaseFileTask().execute();
Run Code Online (Sandbox Code Playgroud)
如您所见,我在新的ProgressDialog调用中使用ctx作为Context变量,如何将上下文传递给调用方法?
到这一个:
new ExportDatabaseFileTask().execute();*
Run Code Online (Sandbox Code Playgroud)
我找到了方法,我必须创建自己的构造函数,并失去静态的东西
public ExportDatabaseFileTask(Context ctx) {
super();
this.ctx=ctx;
dialog= new ProgressDialog(ctx);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1691 次 |
| 最近记录: |