当前位置: 首页>>代码示例>>Java>>正文


Java AsyncTask.execute方法代码示例

本文整理汇总了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();
            }
        }
    });
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:20,代码来源:DateTakenRetriever.java

示例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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:26,代码来源:BusinessCardActivity.java

示例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);
    }

}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:24,代码来源:LoginButton.java

示例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();
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:26,代码来源:SelfAware.java

示例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;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:19,代码来源:GpgsClient.java

示例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));
            }
        });
    }
}
 
开发者ID:10clouds,项目名称:InifiniteRecyclerView,代码行数:19,代码来源:AbstractInfiniteAdapter.java

示例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");
                }
            }
        }
    });
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:42,代码来源:FragmentSettingsHelper.java

示例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);
        }
    });
}
 
开发者ID:brenopolanski,项目名称:android-movies-app,代码行数:12,代码来源:MoviesUtil.java

示例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());
}
 
开发者ID:seaase,项目名称:ArscEditor,代码行数:8,代码来源:MainActivity.java

示例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();

}
 
开发者ID:dobragab,项目名称:Mi5CameraCalibrate,代码行数:15,代码来源:BootReceiver.java

示例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);
            }
        }
    });
}
 
开发者ID:AbduazizKayumov,项目名称:Flashcard-Maker-Android,代码行数:37,代码来源:FlashcardActivity.java

示例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(), "");
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:32,代码来源:SaiyAccessibilityService.java

示例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);
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:34,代码来源:DialogUtils.java

示例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");
                }
            }
        }
    });
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:39,代码来源:FragmentSuperuserHelper.java

示例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;
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:39,代码来源:WaterReminderFirebaseJobService.java


注:本文中的android.os.AsyncTask.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。