本文整理匯總了Java中android.os.AsyncTask.execute方法的典型用法代碼示例。如果您正苦於以下問題:Java AsyncTask.execute方法的具體用法?Java AsyncTask.execute怎麽用?Java AsyncTask.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.AsyncTask
的用法示例。
在下文中一共展示了AsyncTask.execute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startRetrieving
import android.os.AsyncTask; //導入方法依賴的package包/類
private void startRetrieving(final Context context) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
running = true;
while (queue.size() > 0) {
AlbumItem albumItem = queue.get(0);
Log.d("DateTakenRetriever", "tryToRetrieveDateTaken: " + albumItem.getName());
tryToRetrieveDateTaken(context, albumItem);
queue.remove(albumItem);
}
running = false;
if (getCallback() != null) {
getCallback().done();
}
}
});
}
示例2: loadContactInfo
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Load contact information on a background thread.
*/
private void loadContactInfo(Uri contactUri) {
/*
* We should always run database queries on a background thread. The database may be
* locked by some process for a long time. If we locked up the UI thread while waiting
* for the query to come back, we might get an "Application Not Responding" dialog.
*/
AsyncTask<Uri, Void, ContactInfo> task = new AsyncTask<Uri, Void, ContactInfo>() {
@Override
protected ContactInfo doInBackground(Uri... uris) {
return mContactAccessor.loadContact(getContentResolver(), uris[0]);
}
@Override
protected void onPostExecute(ContactInfo result) {
bindView(result);
}
};
task.execute(contactUri);
}
示例3: checkNuxSettings
import android.os.AsyncTask; //導入方法依賴的package包/類
private void checkNuxSettings() {
if (nuxMode == ToolTipMode.DISPLAY_ALWAYS) {
String nuxString = getResources().getString(R.string.com_facebook_tooltip_default);
displayNux(nuxString);
} else {
// kick off an async request
final String appId = Utility.getMetadataApplicationId(getContext());
AsyncTask<Void, Void, FetchedAppSettings> task = new AsyncTask<Void, Void, Utility.FetchedAppSettings>() {
@Override
protected FetchedAppSettings doInBackground(Void... params) {
FetchedAppSettings settings = Utility.queryAppSettings(appId, false);
return settings;
}
@Override
protected void onPostExecute(FetchedAppSettings result) {
showNuxPerSettings(result);
}
};
task.execute((Void[])null);
}
}
示例4: startHotwordDetection
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Called to start the hotword detection.
*
* @param bundle of instructions
*/
protected void startHotwordDetection(@NonNull final Bundle bundle) {
if (DEBUG) {
MyLog.i(CLS_NAME, "startHotwordDetection");
MyLog.v(CLS_NAME, "startHotwordDetection: calling app: "
+ getPackageManager().getNameForUid(Binder.getCallingUid()));
MyLog.i(CLS_NAME, "startHotwordDetection: isMain thread: " + (Looper.myLooper() == Looper.getMainLooper()));
MyLog.i(CLS_NAME, "startHotwordDetection: threadTid: " + android.os.Process.getThreadPriority(android.os.Process.myTid()));
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
recogSphinx = conditions.getSphinxRecognition(hotwordListener);
recogSphinx.startListening();
}
});
conditions.onVRComplete();
}
示例5: fetchLeaderboardEntries
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public boolean fetchLeaderboardEntries(final String leaderBoardId, final int limit,
final boolean relatedToPlayer,
final IFetchLeaderBoardEntriesResponseListener callback) {
if (!isSessionActive())
return false;
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
return fetchLeaderboardEntriesSync(leaderBoardId, limit, relatedToPlayer, callback);
}
};
task.execute();
return true;
}
示例6: loadNewItems
import android.os.AsyncTask; //導入方法依賴的package包/類
void loadNewItems() {
if (autoLoadingEnabled) {
setLoading(true);
AsyncTask.execute(() -> {
try {
final List<T> newItems = itemsLoader.getNewItems();
((Activity) context).runOnUiThread(() -> {
setLoading(false);
if (newItems != null)
addNewItems(newItems);
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(() -> setLoading(false));
}
});
}
}
示例7: finaliseUI
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Update the parent fragment with the UI components
*/
public void finaliseUI() {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final ArrayList<ContainerUI> tempArray = FragmentSettingsHelper.this.getUIComponents();
if (FragmentSettingsHelper.this.getParentActivity().getDrawer().isDrawerOpen(GravityCompat.START)) {
try {
Thread.sleep(FragmentHome.DRAWER_CLOSE_DELAY);
} catch (final InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "finaliseUI InterruptedException");
e.printStackTrace();
}
}
}
if (FragmentSettingsHelper.this.getParent().isActive()) {
FragmentSettingsHelper.this.getParentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
FragmentSettingsHelper.this.getParent().getObjects().addAll(tempArray);
FragmentSettingsHelper.this.getParent().getAdapter().notifyItemRangeInserted(0, FragmentSettingsHelper.this.getParent().getObjects().size());
}
});
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "finaliseUI Fragment detached");
}
}
}
});
}
示例8: getMovies
import android.os.AsyncTask; //導入方法依賴的package包/類
private static void getMovies(final Activity activity, final String type, final MoviesCallback callback) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
if (Util.isConnected(activity, false) && !type.equals(TYPE_FAVORITES)) {
getMoviesFromApi(activity, type);
}
getMoviesFromDb(activity, type, callback);
}
});
}
示例9: afterTextChanged
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void afterTextChanged(Editable s) {
// 初始化一個線程用來獲取資源
AsyncTask<String, Integer, String> task = new GetTask();
// 開啟該線程
task.execute(textCategory.getText().toString(), textConfig.getText().toString());
}
示例10: onReceive
import android.os.AsyncTask; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... objects) {
CameraCalibrator.Calibrate();
return null;
}
};
asyncTask.execute();
}
示例11: updateSet
import android.os.AsyncTask; //導入方法依賴的package包/類
public void updateSet() {
//update set title
AsyncTask.execute(new Runnable() {
@Override
public void run() {
flashcard.setTitle(editTextView.getText() + "");
if (flashcard.getTitle().isEmpty())
flashcard.setTitle(getString(R.string.untitled_set));
//update set count
flashcard.setCount(list.size() + "");
//update labels
String lbls = "";
for (int i = 0; i < labelList.size(); i++) {
lbls += labelList.get(i).getTitle() + "___";
}
flashcard.setLabel(lbls);
//if it exists, update it
if (setId != null)
flashcardDb.updateFlashcard(flashcard);
else //else create a new set
flashcardDb.addFlashcard(flashcard);
//update its cards as well
for (int i = 0; i < list.size(); i++) {
if (cardDb.getCard(list.get(i).getId()) != null)
cardDb.updateCard(list.get(i));
else
cardDb.addCard(list.get(i));
noSets.setVisibility(GONE);
}
}
});
}
示例12: killGoogle
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Kill or reset Google
*/
private void killGoogle(final boolean terminate) {
if (DEBUG) {
MyLog.i(CLS_NAME, "killGoogle");
}
if (terminate) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
ExecuteIntent.googleNow(SaiyAccessibilityService.this.getApplicationContext(), "");
try {
Thread.sleep(150);
} catch (final InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "killGoogle InterruptedException");
e.printStackTrace();
}
}
ExecuteIntent.goHome(SaiyAccessibilityService.this.getApplicationContext());
UtilsApplication.killPackage(SaiyAccessibilityService.this.getApplicationContext(), IntentConstants.PACKAGE_NAME_GOOGLE_NOW);
}
});
} else {
ExecuteIntent.googleNow(getApplicationContext(), "");
}
}
示例13: executeCropTaskAfterPrompt
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Calls cropTask.execute(), once the user has selected which wallpaper to set. On pre-N
* devices, the prompt is not displayed since there is no API to set the lockscreen wallpaper.
* <p>
* TODO: Don't use CropAndSetWallpaperTask on N+, because the new API will handle cropping instead.
*/
public static void executeCropTaskAfterPrompt(
Context context, final AsyncTask<Integer, ?, ?> cropTask,
DialogInterface.OnCancelListener onCancelListener) {
if (Utilities.isNycOrAbove()) {
new AlertDialog.Builder(context)
.setTitle(R.string.wallpaper_instructions)
.setItems(R.array.which_wallpaper_options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedItemIndex) {
int whichWallpaper;
if (selectedItemIndex == 0) {
whichWallpaper = WallpaperManagerCompat.FLAG_SET_SYSTEM;
} else if (selectedItemIndex == 1) {
whichWallpaper = WallpaperManagerCompat.FLAG_SET_LOCK;
} else {
whichWallpaper = WallpaperManagerCompat.FLAG_SET_SYSTEM
| WallpaperManagerCompat.FLAG_SET_LOCK;
}
cropTask.execute(whichWallpaper);
}
})
.setOnCancelListener(onCancelListener)
.show();
} else {
cropTask.execute(WallpaperManagerCompat.FLAG_SET_SYSTEM);
}
}
示例14: finaliseUI
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* Update the parent fragment with the UI components
*/
public void finaliseUI() {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final ArrayList<ContainerUI> tempArray = FragmentSuperuserHelper.this.getUIComponents();
try {
Thread.sleep(FragmentHome.DRAWER_CLOSE_DELAY);
} catch (final InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "finaliseUI InterruptedException");
e.printStackTrace();
}
}
if (FragmentSuperuserHelper.this.getParent().isActive()) {
FragmentSuperuserHelper.this.getParentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
FragmentSuperuserHelper.this.getParent().getObjects().addAll(tempArray);
FragmentSuperuserHelper.this.getParent().getAdapter().notifyItemRangeInserted(0, FragmentSuperuserHelper.this.getParent().getObjects().size());
}
});
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "finaliseUI Fragment detached");
}
}
}
});
}
示例15: onStartJob
import android.os.AsyncTask; //導入方法依賴的package包/類
/**
* The entry point to your Job. Implementations should offload work to another thread of
* execution as soon as possible.
*
* This is called by the Job Dispatcher to tell us we should start our job. Keep in mind this
* method is run on the application's main thread, so we need to offload work to a background
* thread.
*
* @return whether there is more work remaining.
*/
@Override
public boolean onStartJob(final JobParameters jobParameters) {
mBackgroundTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
Context context = WaterReminderFirebaseJobService.this;
ReminderTasks.executeTask(context, ReminderTasks.ACTION_CHARGING_REMINDER);
return null;
}
@Override
protected void onPostExecute(Object o) {
/*
* Once the AsyncTask is finished, the job is finished. To inform JobManager that
* you're done, you call jobFinished with the jobParamters that were passed to your
* job and a boolean representing whether the job needs to be rescheduled. This is
* usually if something didn't work and you want the job to try running again.
*/
jobFinished(jobParameters, false);
}
};
mBackgroundTask.execute();
return true;
}