Android AsyncTask - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AsyncTask class.

This code example shows how to use the following methods:execute
 */ 
public final class DefaultAsyncTaskExecInterface implements AsyncTaskExecInterface { 
 
  @Override 
  public <T> void execute(AsyncTask<T,?,?> task, T... args) {
    task.execute(args);
  } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeOnExecutor
@TargetApi(11) 
public final class HoneycombAsyncTaskExecInterface implements AsyncTaskExecInterface { 
 
  @Override 
  public <T> void execute(AsyncTask<T,?,?> task, T... args) {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
  } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeOnExecutor
    taskExec = new AsyncTaskExecManager().build();
    powerStatusReceiver = new PowerStatusReceiver();
    onActivity(); 
  } 
 
  synchronized void onActivity() { 
    cancel(); 
    inactivityTask = new InactivityAsyncTask();
    taskExec.execute(inactivityTask);
  } 
 
  public void onPause() { 
    cancel(); 
    activity.unregisterReceiver(powerStatusReceiver);
  } 
 
  public void onResume(){ 
    activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    onActivity(); 
  } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute, executeOnExecutor
    @TargetApi(11) 
    public static <T> void executeAsyncTask(AsyncTask<T, ?, ?> task, T... args) {
        // TODO figure out how to subclass abstract and generalized AsyncTask, 
        // then put this there 
        if (AndroidUtils.isHoneycombOrHigher()) { 
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
        } else { 
            task.execute(args);
        } 
    } 
 
    /** 
     * Returns an {@link InputStream} using {@link HttpURLConnection} to connect 
     * to the given URL. 
     */ 
    public static InputStream downloadUrl(String urlString) throws IOException {
        HttpURLConnection conn = buildHttpUrlConnection(urlString);
        conn.connect();
 
        InputStream stream = conn.getInputStream();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:cancel, getStatus
     * @param theTask {@link AsyncTask} to be checked. 
     * @return True if the task is running, false otherwise. 
     */ 
    public static boolean isRunning(final AsyncTask<?, ?, ?> theTask) {
        return (theTask != null && 
                theTask.getStatus().equals(AsyncTask.Status.RUNNING));
    } 
 
    /** 
     * Abort the running task. 
     * 
     * @param theTask 
     * @return True if the task has been successfully aborted. False otherwise. 
     */ 
    public static boolean abort(AsyncTask<?, ?, ?> theTask) {
        if (!AsyncTaskUtils.isRunning(theTask)) {
            return false; 
        } 
        theTask.cancel(true);
        theTask = null;

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:execute
                                          T... params) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } 
    else { 
      task.execute(params);
    } 
  } 
 
  private class ContentsLoadTask extends AsyncTask<Context, Void, Void> {
    private BookContents localContents=null;
    private Exception e=null;
 
    @Override 
    protected Void doInBackground(Context... ctxt) {
      try { 
        StringBuilder buf=new StringBuilder();
        InputStream json=ctxt[0].getAssets().open("book/contents.json");
        BufferedReader in=
            new BufferedReader(new InputStreamReader(json));
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:cancel
 
  @Override 
  protected void onPause() { 
    AsyncTask<?,?,?> oldTask = networkTask;
    if (oldTask != null) {
      oldTask.cancel(true);
      networkTask = null;
    } 
    super.onPause(); 
  } 
 
  private void launchSearch() { 
    String query = queryTextView.getText().toString();
    if (query != null && !query.isEmpty()) {
      AsyncTask<?,?,?> oldTask = networkTask;
      if (oldTask != null) {
        oldTask.cancel(true);
      } 
      networkTask = new NetworkTask();
      networkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query, isbn);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeOnExecutor
@TargetApi(11) 
public final class HoneycombAsyncTaskExecInterface implements AsyncTaskExecInterface { 
 
  @Override 
  public <T> void execute(AsyncTask<T,?,?> task, T... args) {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args);
  } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeOnExecutor
 
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SDK11 { 
 
    public static <P> void executeOnThreadPool(AsyncTask<P, ?, ?> task, P... params) {
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
    } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:cancel, getStatus
package br.com.caelum.ondeestaobusao.util; 
 
import android.os.AsyncTask; 
import android.os.AsyncTask.Status; 
 
public class CancelableAssynTask { 
 
	public static void cancel(AsyncTask<?,?,?> task) {
		if (task != null && Status.RUNNING.equals(task.getStatus())) {
			task.cancel(true);
		} 
	} 
 
	public static boolean isRunning(AsyncTask<?,?,?> task) {
		if (task != null && Status.RUNNING.equals(task.getStatus())) {
			return true; 
		} 
		return false; 
	} 
} 

6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android AsyncTask Questions & Answers:

Other Android AsyncTask Examples

3:		 * */
4:		private class loadMoreListView extends AsyncTask<Void, Void, Void> {
5:	
6:			@Override
7:			protected void onPreExecute() {

Read More

21:		
22:		// Asyntask
23:		AsyncTask<Void, Void, Void> mRegisterTask;
24:		
25:		// Alert dialog manager
-
84:					// hence the use of AsyncTask instead of a raw thread.
85:					final Context context = this;
86:					mRegisterTask = new AsyncTask<Void, Void, Void>() {
87:	
88:						@Override

Read More

39:		 * Background Async task to load user profile picture from url
40:		 * */
41:		private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
42:			ImageView bmImage;
43:

Read More

See Code Examples for Android AsyncTask Methods: