单击按钮调用此方法:
private void goRegister(final boolean isUsername) {
new Loading.LoadTast(ctx) {
@Override
protected String doInBackground(Integer... params) {
Looper.prepare();
String msg=doRegister(isUsername);
closeProgressDialog();
if(msg == null || msg.length() == 0) {
SmartNgApplication.getInstance().exit();
} else {
BaseHelper.showToast(ctx, msg);
}
Looper.loop();
return null;
}
}.execute();
}
这是 LoadTast 类:
public abstract static class LoadTast extends AsyncTask <Integer, Integer, String > {
private ProgressDialog progressDialog;
private Context ctx;
public LoadTast(Context ctx) {
this.ctx=ctx;
}
protected abstract String doInBackground(Integer... params);
public void onPreExecute() {
super.onPreExecute();
progressDialog=ProgressDialog.show(ctx, "", "loading...", true, false);
}
public void onPostExecute(String result) {
super.onPostExecute(result);
progressDialog.dismiss();
BaseHelper.showToast(ctx, result);
}
public void closeProgressDialog() {
if(progressDialog != null) {
progressDialog.dismiss();
}
}
}
我的程序是:当我点击 5 次按钮时不调用doInbackground
方法并且屏幕总是运行加载。我猜代码是 runonPreExecute
而不是 run doInbackground
。为什么??在AsyncTask
有一个线程池,CORE_POOL_SIZE=5
. 程序如何解决,帮帮我,谢谢!