Example usage for android.os AsyncTask THREAD_POOL_EXECUTOR

List of usage examples for android.os AsyncTask THREAD_POOL_EXECUTOR

Introduction

In this page you can find the example usage for android.os AsyncTask THREAD_POOL_EXECUTOR.

Prototype

Executor THREAD_POOL_EXECUTOR

To view the source code for android.os AsyncTask THREAD_POOL_EXECUTOR.

Click Source Link

Document

An Executor that can be used to execute tasks in parallel.

Usage

From source file:net.e_fas.oss.tabijiman.MapsActivity.java

public void query(String query, String category) throws UnsupportedEncodingException {

    String url = "http://sparql.odp.jig.jp/api/v1/sparql";
    url += "?output=json&query=" + URLEncoder.encode(query, "UTF-8");

    print("query >> " + query);
    print("url >> " + url);

    new ExecuteSPARQL(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url, category);
}

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

private void loadWallsList(Context context) {
    if (mPrefs.getWallsListLoaded()) {
        WallpapersList.clearList();//from w  w  w. j  a  v a 2s. co m
        mPrefs.setWallsListLoaded(!mPrefs.getWallsListLoaded());
    }
    new WallpapersFragment.DownloadJSON(new WallsListInterface() {
        @Override
        public void checkWallsListCreation(boolean result) {
            mPrefs.setWallsListLoaded(result);
            if (WallpapersFragment.mSwipeRefreshLayout != null) {
                WallpapersFragment.mSwipeRefreshLayout.setEnabled(false);
                WallpapersFragment.mSwipeRefreshLayout.setRefreshing(false);
            }
            if (WallpapersFragment.mAdapter != null) {
                WallpapersFragment.mAdapter.notifyDataSetChanged();
            }
        }
    }, context, WallpapersFragment.noConnection).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

public Executor getCurrentExecutor() {
    final DocumentInfo cwd = getCurrentDirectory();
    if (cwd != null && cwd.authority != null) {
        return ProviderExecutor.forAuthority(cwd.authority);
    } else {/*from  w  ww.j  av  a 2 s .  c  om*/
        return AsyncTask.THREAD_POOL_EXECUTOR;
    }
}

From source file:im.vector.VectorApp.java

/**
 * Init the application locale from the saved one
 *///from  w  ww.j  av  a  2 s  .  co m
private static void initApplicationLocale() {
    Context context = VectorApp.getInstance();
    Locale locale = getApplicationLocale();
    float fontScale = getFontScaleValue();
    String theme = ThemeUtils.getApplicationTheme(context);

    Locale.setDefault(locale);
    Configuration config = new Configuration(context.getResources().getConfiguration());
    config.locale = locale;
    config.fontScale = fontScale;
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

    // init the theme
    ThemeUtils.setApplicationTheme(context, theme);

    // init the known locales in background
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            getApplicationLocales(VectorApp.getInstance());
            return null;
        }
    };

    // should never crash
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void updateDrawer(String path) {
    new AsyncTask<String, Void, Integer>() {
        @Override// w  ww  .  j  a  v  a2  s.  co m
        protected Integer doInBackground(String... strings) {
            String path = strings[0];
            int k = 0, i = 0;
            for (Item item : DataUtils.getList()) {
                if (!item.isSection()) {
                    if (((EntryItem) item).getPath().equals(path))
                        k = i;
                }
                i++;
            }
            return k;
        }

        @Override
        public void onPostExecute(Integer integers) {
            if (adapter != null)
                adapter.toggleChecked(integers);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path);

}

From source file:com.apptentive.android.sdk.ApptentiveInternal.java

private synchronized void asyncFetchConversationToken() {
    if (isConversationTokenFetchPending.compareAndSet(false, true)) {
        AsyncTask<Void, Void, Boolean> fetchConversationTokenTask = new AsyncTask<Void, Void, Boolean>() {
            private Exception e = null;

            @Override/*from  ww w  .j  a  va  2  s. co  m*/
            protected Boolean doInBackground(Void... params) {
                try {
                    return fetchConversationToken();
                } catch (Exception e) {
                    // Hold onto the unhandled exception from fetchConversationToken() for later handling in UI thread
                    this.e = e;
                }
                return false;
            }

            @Override
            protected void onPostExecute(Boolean successful) {
                if (e == null) {
                    // Update pending state on UI thread after finishing the task
                    ApptentiveLog.d("Fetching conversation token asyncTask finished. Successful? %b",
                            successful);
                    isConversationTokenFetchPending.set(false);
                    if (successful) {
                        // Once token is fetched successfully, start asyncTasks to fetch global configuration, then interaction
                        asyncFetchAppConfigurationAndInteractions();
                    }
                } else {
                    ApptentiveLog.w("Unhandled Exception thrown from fetching conversation token asyncTask", e);
                    MetricModule.sendError(e, null, null);
                }
            }

        };

        ApptentiveLog.i("Fetching conversation token asyncTask scheduled.");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            fetchConversationTokenTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            fetchConversationTokenTask.execute();
        }
    } else {
        ApptentiveLog.v("Fetching Configuration pending");
    }
}

From source file:ru.valle.safetrade.SellActivity.java

private void loadState(final long id) {
    cancelAllTasks();//from w w w  .  j  a  v a 2s.  c om
    loadStateTask = new AsyncTask<Void, Void, TradeRecord>() {
        @Override
        protected TradeRecord doInBackground(Void... params) {
            SQLiteDatabase db = DatabaseHelper.getInstance(SellActivity.this).getReadableDatabase();
            if (db != null) {
                Cursor cursor = db.query(DatabaseHelper.TABLE_HISTORY, null, BaseColumns._ID + "=?",
                        new String[] { String.valueOf(id) }, null, null, null);
                ArrayList<TradeRecord> tradeRecords = DatabaseHelper.readTradeRecords(cursor);
                return tradeRecords.isEmpty() ? null : tradeRecords.get(0);
            } else {
                return null;
            }
        }

        @Override
        protected void onPostExecute(final TradeRecord tradeRecord) {
            tradeInfo = tradeRecord;
            loadStateTask = null;
            rowId = tradeRecord.id;
            passwordView.setText(tradeRecord.password);
            intermediateCodeView.setText(tradeRecord.intermediateCode);
            if (confirmationCodeDecodingTask == null) {
                confirmationCodeView.setText(tradeRecord.confirmationCode);
            }
            if (TextUtils.isEmpty(tradeRecord.address)) {
                addressLabelView.setVisibility(View.GONE);
                addressView.setVisibility(View.GONE);
            } else {
                addressView.setText(tradeRecord.address);
                addressLabelView.setVisibility(View.VISIBLE);
                addressView.setVisibility(View.VISIBLE);
            }
            finalAddressView.setText(tradeRecord.destinationAddress);
            if (privateKeyDecodingTask == null) {
                privateKeyView.setText(tradeRecord.encryptedPrivateKey);
            }
            MainActivity.updateBalance(SellActivity.this, id, tradeInfo.address,
                    onAddressStateReceivedListener);
        }
    };
    if (Build.VERSION.SDK_INT >= 11) {
        loadStateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loadStateTask.execute();
    }
}

From source file:com.android.wfds.printservice.WPrintService.java

private static <T extends AbstractMessageTask> void executeTask(T task) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {//from www . j a v a2  s  .  c  o  m
        task.execute();
    }
}

From source file:key.secretkey.crypto.PgpHandler.java

private void setTimer() {
    // If a task already exist, let it finish without clearing the clipboard
    if (delayTask != null) {
        delayTask.setClearClipboard(false);
    }//from w  w  w .  java2  s  .co  m

    delayTask = new DelayShow();
    delayTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.aegiswallet.actions.MainActivity.java

private void encryptWallet(String password) {
    try {//  ww w  .  j av  a2  s . co  m
        EncryptWalletTask encryptWalletTask = new EncryptWalletTask(context, wallet, password, application,
                false);
        Log.d(TAG, "about to do execute...");
        //encryptWalletTask.execute();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            encryptWalletTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        else
            encryptWalletTask.execute();

    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
}