4

我有 TabActivity,每个选项卡都有 ActivityGroup。在 Forth 选项卡中,ForthActivityGroup 有一个 MyAsyncActivity 类。在 MyAsyncAcitivity 我有这个代码。我有这个 Android AsyncTask 代码。在 Android 2.3.3 上调用 doInBackground(String.. params) 并打印日志,但在 Android 4.0 上未打印。请有人给我想法我做什么?

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();
            }

    }
4

1 回答 1

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);
}
于 2013-10-01T09:38:04.843 回答