click the button to call this method:
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();
}
and this is LoadTast class:
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();
}
}
}
my program is:
when I click 5 times the button don’t call doInbackground method and the screen always run a loading. I guess the code is run onPreExecute and not run doInbackground. Why??
in the AsyncTask has a thread pool,the CORE_POOL_SIZE=5. How to solution the program,Help me thank you !
asyncTask isn’t supposed to run its doInBackground more than once , and it’s also not supposed to be a loopy thread .
asyncTask is supposed to be a one time thing that you run , and you can only assume that if multiple asyncTasks have executed , at least one will run at the same time.
another thing i’ve noticed : you called
closeProgressDialogfrom withindoInBackground, but that’s a UI related operation ,while thedoInBackgroundis being ran on a non-UI thread.