Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.TargetApi; import android.os.AsyncTask; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; public class Main { /** * Runs an AsyncTask. These are always executed in parallel, independently of the device's API level. * @param task Task to be run. * @param params Task parameters. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static <Params> void executeAsyncTask(AsyncTask<Params, ?, ?> task, Params... params) { // By default, in Honeycomb and later AsyncTasks execute serially, while they execute // in parallel (using a thread pool) in earlier versions. Force parallelism here. if (isHoneycomb()) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); else task.execute(params); } /** * Returns true if the device has Honeycomb (3.0) or greater installed. */ public static boolean isHoneycomb() { return isApiLevel(VERSION_CODES.HONEYCOMB); // Android 3.0, API Level 11. } /** * Returns true if the device supports the specified API level (or greater). */ public static boolean isApiLevel(int apiLevel) { return (VERSION.SDK_INT >= apiLevel); } }