executeOnExecutor()api 11 才出现的 并行的 效率比execute()高因为execute()是串行的
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import com.qianfeng.xutilsnetwork.tasks.NumberTask;
public class TaskActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.task_activity);
for (int i = 0; i < 10; i++) {
NumberTask task = new NumberTask();
// task.execute("Task" + i);
if(Build.VERSION.SDK_INT >= 11) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "Task" + i);
}else{
task.execute("Task" + i);
}
}
}
}