本文整理了Java中bolts.Task.callInBackground()
方法的一些代码示例,展示了Task.callInBackground()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.callInBackground()
方法的具体详情如下:
包路径:bolts.Task
类名称:Task
方法名:callInBackground
[英]Invokes the callable on a background thread, returning a Task to represent the operation.
[中]在后台线程上调用callable,返回一个任务来表示操作。
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public boolean onStartJob(final JobParameters job) {
PLog.d(ParseGCM.TAG, "Updating GCM token");
Task.callInBackground(new Callable<Void>() {
@Override
public Void call() {
try {
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String senderId = job.getExtras().getString(KEY_GCM_SENDER_ID);
String token = instanceID.getToken(senderId,
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.setDeviceToken(token);
//even though this is FCM, calling it gcm will work on the backend
installation.setPushType(PUSH_TYPE);
installation.save();
PLog.d(ParseGCM.TAG, "GCM registration success");
} catch (Exception e) {
PLog.e(ParseGCM.TAG, "GCM registration failed", e);
jobFinished(job, true);
}
return null;
}
});
return true; // Answers the question: "Is there still work going on?"
}
代码示例来源:origin: parse-community/Parse-SDK-Android
for (int i = 0; i < 20; i++) {
final int number = i;
Task<Void> task = Task.callInBackground(new Callable<Void>() {
@Override
public Void call() throws Exception {
代码示例来源:origin: parse-community/Parse-SDK-Android
Task.callInBackground(new Callable<Void>() {
@Override
public Void call() {
代码示例来源:origin: mbientlab/MetaWear-SDK-Android
@Override
public Task<File> downloadFileAsync(final String srcUrl, final String dest) {
final Capture<HttpURLConnection> urlConn = new Capture<>();
return Task.callInBackground(() -> {
URL fileUrl = new URL(srcUrl);
urlConn.set((HttpURLConnection) fileUrl.openConnection());
代码示例来源:origin: fr.avianey/bolts-android-api
final Capture<String> content = new Capture<String>();
final Capture<String> contentType = new Capture<String>();
return Task.callInBackground(new Callable<Void>() {
@Override
public Void call() throws Exception {
内容来源于网络,如有侵权,请联系作者删除!