當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。