本文整理汇总了Java中android.os.AsyncTask.executeOnExecutor方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncTask.executeOnExecutor方法的具体用法?Java AsyncTask.executeOnExecutor怎么用?Java AsyncTask.executeOnExecutor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.AsyncTask
的用法示例。
在下文中一共展示了AsyncTask.executeOnExecutor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeTask
import android.os.AsyncTask; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static <A, B, C> void executeTask(AsyncTask<A, B, C> task, A... params ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
else {
task.execute(params);
}
}
示例2: sendMessage
import android.os.AsyncTask; //导入方法依赖的package包/类
public void sendMessage(final String message){
if (mRun) {
AsyncTask<Void, Void, Boolean> sendThread = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
Log.d("ConnectionService", "Sending: " + message);
if (out != null && !out.checkError()) {
out.println(message);
out.flush();
}
return null;
}
};
sendThread.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
示例3: initializeCircumvention
import android.os.AsyncTask; //导入方法依赖的package包/类
private void initializeCircumvention() {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (new SignalServiceNetworkAccess(ApplicationContext.this).isCensored(ApplicationContext.this)) {
try {
//NOGMS ProviderInstaller.installIfNeeded(ApplicationContext.this);
} catch (Throwable t) {
Log.w(TAG, t);
}
}
return null;
}
};
if (Build.VERSION.SDK_INT >= 11) task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else task.execute();
}
示例4: decodeFileAtAsync
import android.os.AsyncTask; //导入方法依赖的package包/类
private void decodeFileAtAsync(
final int index,
final int size,
final OnBitmapLoadedListener listener) {
AsyncTask<Void, Void, OrientedBitmap> task =
new AsyncTask<Void, Void, OrientedBitmap>() {
@Override
public OrientedBitmap doInBackground(Void... nothings) {
return decodeFileAt(index, size);
}
@Override
protected void onPostExecute(OrientedBitmap orientedBitmap) {
if (orientedBitmap != null) {
listener.onBitmapLoaded(
orientedBitmap.bitmap,
orientedBitmap.orientation);
} else {
listener.onBitmapLoaded(null, 0);
}
}
};
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// from DONUT until HONEYCOMB AsyncTask had a pool of threads
// allowing multiple tasks to operate in parallel
task.execute();
} else {
// starting with HONEYCOMB, tasks are executed on a single
// thread (what would mean this task would block all other
// AsyncTask's) unless executeOnExecutor() is used
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
示例5: loadMusic
import android.os.AsyncTask; //导入方法依赖的package包/类
public static void loadMusic(final Context context, final MusicLoaderListener loaderListener) {
final AsyncTask<Void, Void, Void> loadTask = new AsyncTask<Void, Void, Void>() {
String[] resp = {"", ""};
List<MediaMetaData> listMusic = new ArrayList<>();
@Override
protected Void doInBackground(Void... voids) {
//resp = getDataResponse();
String response = loadJSONFromAsset(context);
listMusic = getMusicList(response, "music");
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (loaderListener != null && listMusic != null && listMusic.size() >= 1) {
loaderListener.onLoadSuccess(listMusic);
} else {
loaderListener.onLoadFailed();
}
}
};
loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
示例6: executeAsyncTask
import android.os.AsyncTask; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private < T > void executeAsyncTask(AsyncTask< T, ?, ? > asyncTask, T... params) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
} else {
asyncTask.execute(params);
}
}
示例7: execUi
import android.os.AsyncTask; //导入方法依赖的package包/类
public static <A, B, C> void execUi(AsyncTask<A, B, C> task, A... params) {
if (task != null) {
if (VERSION.SDK_INT < 11) {
task.execute(params);
} else {
task.executeOnExecutor(uiExecutor, params);
}
}
}
示例8: executeAsyncTask
import android.os.AsyncTask; //导入方法依赖的package包/类
/**
* Execute async task on single thread Executer or cached thread pool Executer.
*
* @param singleThread True if needs to be executed on single thread Executer, otherwise it will
* use cached thread pool Executer.
* @param task Async task to execute.
* @param params Params.
*/
public static <T> void executeAsyncTask(boolean singleThread, AsyncTask<T, ?, ?> task,
T... params) {
if (singleThread) {
task.executeOnExecutor(singleThreadExecutor, params);
} else {
task.executeOnExecutor(asyncExecutor, params);
}
}
示例9: executeAsyncTask
import android.os.AsyncTask; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
static public <T> void executeAsyncTask(AsyncTask<T, ?, ?> task, T... params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
else {
task.execute(params);
}
}
示例10:
import android.os.AsyncTask; //导入方法依赖的package包/类
/**
* Concurrently executes AsyncTask on any Android version
* @param task to execute
* @param params for task
* @return executing AsyncTask
*/
@SuppressLint("NewApi")
public static <Params, Progress, Result> AsyncTask<Params, Progress, Result>
executeConcurrently(AsyncTask<Params, Progress, Result> task,
Params... params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(concurrentExecutor, params);
} else {
task.execute(params);
}
return task;
}
示例11: execute
import android.os.AsyncTask; //导入方法依赖的package包/类
/**
* Execute an {@link android.os.AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link android.os.AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
@SafeVarargs
public static <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);
}
}
示例12: async
import android.os.AsyncTask; //导入方法依赖的package包/类
public static AsyncTask async(final Runnable r, boolean multi) {
AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
r.run();
return null;
}
};
if (multi) {
at.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
at.execute();
}
return at;
}
示例13: runTask
import android.os.AsyncTask; //导入方法依赖的package包/类
public <T> void runTask(Uri uri, AsyncTask<T, ?, ?> task, T... args) {
synchronized (mTasks) {
if (!mTasks.containsKey(uri) || mTasks.get(uri).getStatus() == Status.FINISHED) {
mTasks.put(uri, task);
// TODO: Use different executor for different servers.
task.executeOnExecutor(mExecutor, args);
} else {
Log.i(TAG,
"Ignore this task for " + uri + " to avoid running multiple updates at the same time.");
}
}
}
示例14: runAsyncTask
import android.os.AsyncTask; //导入方法依赖的package包/类
private AsyncTask<Void, GitHubUser, GitHubUser> runAsyncTask(AsyncTask<Void, GitHubUser, GitHubUser> task)
{
return task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
示例15: runAsyncTask
import android.os.AsyncTask; //导入方法依赖的package包/类
public static AsyncTask<Void, Void, Void> runAsyncTask(AsyncTask<Void, Void, Void> task, String id)
{
return task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}