本文整理匯總了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);
}