Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active January 3, 2016 10:39
Show Gist options
  • Save benigumocom/8450717 to your computer and use it in GitHub Desktop.
Save benigumocom/8450717 to your computer and use it in GitHub Desktop.
バージョンによるAsyncTaskのスケジューリング問題回避
/*
1.6 以前は、シングルスレッドで順番に実行される
1.6 から 2.3、スレッドプールで並列に実行される。
3.0 以降、デフォルトで以前の動作に戻る。スレッドプール利用はexecuteOnExecutor()で。
今どきの端末ではデフォルトでは並列実行されない。
*/
public class ConcurrentAsyncTask {
public static void execute(AsyncTask as) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
as.execute();
} else {
as.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment