-
-
Save johnkil/2935031 to your computer and use it in GitHub Desktop.
Thread poll AsyncTask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute an {@link AsyncTask} on a thread pool. | |
* | |
* @param task Task to execute. | |
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}. | |
* @param <T> Task argument type. | |
*/ | |
public <T> void execute(AsyncTask<T, ?, ?> task, T... args) { | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) { | |
throw new UnsupportedOperationException("This class can only be used on API 4 and newer."); | |
} | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { | |
task.execute(args); | |
} else { | |
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment