我有TabActivity,每个标签都有ActivityGroup。在Forth Tab中,ForthActivityGroup有一个MyAsyncActivity类。在MyAsyncAcitivity中,我有这个代码。 我有这个Android AsyncTask代码。调用doInBackground(String .. params)并在Android 2.3.3上打印日志,但不在Android 4.0上打印。请SomeBody告诉我我的想法?
public class getXML extends AsyncTask<String, Integer, String>{
private final ProgressDialog dialog = new ProgressDialog(this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Loading...");
this.dialog.show();
}
@Override
protected String doInBackground(String... params) {
Log.d("Payment", "do background");
return "result";
}
@Override
protected void onPostExecute(String result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
答案 0 :(得分:3)
使用此:
AsyncTask task = new YourTask();
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute(params);
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}