List of usage examples for android.os AsyncTask cancel
public final boolean cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task.
From source file:com.androidbase.activities.BaseActivity.java
public void cancelAsyncTask(AsyncTask<?, ?, ?> task) { if (task != null) { task.cancel(true); } }
From source file:simple.android.SimpleFragment.java
@Override public void onDestroy() { if (getActivity().isFinishing()) { ArrayList<AsyncTask<Void, Void, Void>> tasks = mState.getAsyncTasks(); for (AsyncTask<Void, Void, Void> asyncTask : tasks) { asyncTask.cancel(false); // TODO: should this be true? }//from ww w . j a va 2s. c o m } super.onDestroy(); }
From source file:com.opemind.cartspage.client.android.book.SearchBookContentsActivity.java
@Override protected void onPause() { AsyncTask<?, ?, ?> oldTask = networkTask; if (oldTask != null) { oldTask.cancel(true); networkTask = null;//ww w. j ava 2 s . c om } super.onPause(); }
From source file:com.opemind.cartspage.client.android.book.SearchBookContentsActivity.java
private void launchSearch() { String query = queryTextView.getText().toString(); if (query != null && !query.isEmpty()) { AsyncTask<?, ?, ?> oldTask = networkTask; if (oldTask != null) { oldTask.cancel(true); }// w ww. j a v a 2 s . com networkTask = new NetworkTask(); networkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query, isbn); headerView.setText(R.string.msg_sbc_searching_book); resultListView.setAdapter(null); queryTextView.setEnabled(false); queryButton.setEnabled(false); } }
From source file:com.yattatech.dbtc.activity.GenericFragmentActivity.java
protected void cancelAsyncTask(AsyncTask<?, ?, ?> asyncTask) { Debug.d(mTag, "cancelAsyncTask"); if ((asyncTask != null) && (asyncTask.getStatus() != Status.FINISHED)) { try {//from w w w.j a v a 2 s . c o m asyncTask.cancel(true); } catch (Exception e) { Debug.e(mTag, "Failed:", e); } } }
From source file:com.concentricsky.android.khanacademy.app.SignInActivity.java
/** * Cancel tasks on pause. /*from ww w . j a va2s .c o m*/ */ @Override protected void onPause() { super.onPause(); // Show no activity transition animation; we want to appear as if we're the same activity as the underlying ShowProfileActivity. overridePendingTransition(0, 0); for (@SuppressWarnings("rawtypes") AsyncTask t : currentTasks) { t.cancel(true); } }
From source file:com.numenta.taurus.TaurusBaseActivity.java
/** * Cancel background task previously tracked via {@link #trackBackgroundTask(android.os.AsyncTask)} * * @param task The task to cancel/* w w w .j ava 2 s.c o m*/ */ public void cancelTrackedBackgroundTask(AsyncTask task) { if (_taskList != null && task != null) { task.cancel(true); _taskList.remove(task); } }
From source file:org.xwiki.android.authenticator.auth.AuthenticatorActivity.java
private void clearAsyncTask() { Iterator<AsyncTask<Void, Void, Object>> iterator = mAsyncTasks.iterator(); while (iterator.hasNext()) { AsyncTask<Void, Void, Object> asyncTask = iterator.next(); if (asyncTask != null && !asyncTask.isCancelled()) { asyncTask.cancel(true); }// ww w. j av a 2 s .com } mAsyncTasks.clear(); }
From source file:com.example.httpjson.AppEngineClient.java
public String getTokenFromServer() { String s = null;/*from w w w .j av a 2 s . co m*/ try { URL uri = new URL("https://rtonames.sprintlabs.io/token"); Map<String, List<String>> headers = new HashMap<String, List<String>>(); String key = "Authorization"; String authStr = "6eece178-9fcf-45b7-ab50-08b8066daabe:e494a4e72b6f7c7672b74d311cbabf2672be8c24c9496554077936097195a5ac69b6acd11eb09a1ae07a40d2e7f0348d"; String encoding = Base64.encodeToString(authStr.getBytes(), Base64.DEFAULT); encoding = encoding.replace("\n", "").replace("\r", ""); System.out.println(encoding); List<String> value = Arrays.asList("Basic " + encoding); headers.put(key, value); AppEngineClient aec1 = new AppEngineClient(); Request request = aec1.new GET(uri, headers); AsyncTask<Request, Void, Response> obj = new asyncclass().execute(request); Response response = obj.get(); obj.cancel(true); obj = null; String body = null; try { body = new String(response.body, "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JSONObject tokenjson = AppEngineClient.getJSONObject(body); if (tokenjson.has("token")) { try { s = tokenjson.getString("token"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; }
From source file:com.numenta.taurus.TaurusBaseActivity.java
@Override protected void onPause() { Log.i(TAG, "{TAG:ANDROID.APP.PAUSE}"); super.onPause(); LocalBroadcastManager.getInstance(this).unregisterReceiver(_isRefreshingReceiver); // Cancel pending tasks if (_taskList != null) { AsyncTask task; while ((task = _taskList.poll()) != null) { if (isFinishing()) { task.cancel(true); }/*from w ww. ja v a 2s. c om*/ } } }