Android examples for android.os:AsyncTask
execute AsyncTask and catch RejectedExecutionException
import java.util.concurrent.RejectedExecutionException; import android.annotation.SuppressLint; import android.os.AsyncTask; import android.os.Build; public class Main { @SuppressLint("NewApi") public static <T> void executeTask(AsyncTask<T, ?, ?> task, T... params) { try {/*from w w w . jav a 2 s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { task.execute(params); } } catch (RejectedExecutionException e) { executeTask(task, params); } catch (IllegalStateException e) { } } }