这是我的任务:
public class GetTask extends AsyncTask<String, Void, JSONObject> {
// callback
private Activity activity;
private AsyncTaskCompleteListener callback;
private AppUtils appUtils;
private ProgressDialog dialog;
private String object;
public GetTask(Activity act){
this.activity = act;
this.callback = (AsyncTaskCompleteListener)act;
}
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(activity);
dialog.setTitle("Load...");
dialog.setMessage("Data...");
dialog.setCancelable(true);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
cancel(false);
}
});
dialog.show();
}
protected JSONObject doInBackground(String... url) {
String link = url[0];
object = AppUtils.cutStringAfter(link);
link = AppUtils.cutStringBefore(link);
return AppUtils.getJSONData(link);
}
protected void onPostExecute(JSONObject result) {
if (null != dialog && dialog.isShowing()) {
dialog.dismiss();
}
super.onPostExecute(result);
callback.onTaskComplete(result, object);
}
@Override
protected void onCancelled()
{
if (this.dialog != null) {
this.dialog.dismiss();
}
}
}
onTaskComplete 调用其他程序解析数据:
@Override
public void onTaskComplete(JSONObject result, String object) {
try {
setDBDATA(result, object);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
完成过程 setDBDATA(result, object); 后对话框关闭,而 setDBDATA 工作时,ProgressDialog 冻结。
如何在回调程序之前关闭ProgressDialog,或者防止冻结他?