Handler post - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Handler post method.

This code example shows how to use the following methods: post
    final Handler handler = new Handler();
    Timer t = new Timer();
    t.schedule(new TimerTask() {
      @Override 
      public void run() { 
        handler.post(new Runnable() {
          public void run() { 
            // This will kill the parent, a bad idea. 
//            parent.finish(); 
            // This will start the browser, a better idea 
            launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/")));
          } 
        }); 
      } 
    }, DELAY_MS);
  } 
} 
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
        if (DEBUG) Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
                mUmsAvailable, Environment.getExternalStorageState()));
         
        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
        thr.start();
        mAsyncEventHandler = new Handler(thr.getLooper());
 
        onUsbMassStorageConnectionChanged(connected);
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
    public void onUsbMassStorageConnectionChanged(final boolean connected) {
        mAsyncEventHandler.post(new Runnable() {
            @Override 
            public void run() { 
                onUsbMassStorageConnectionChangedAsync(connected);
            } 
        }); 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
     * @param itemId a string identifying the item 
     * @param quantity the quantity of items in this purchase 
     */ 
    void postPurchaseStateChange(final PurchaseState purchaseState, final String itemId,
            final int quantity, final long purchaseTime, final String developerPayload) {
        mHandler.post(new Runnable() {
            @Override 
            public void run() { 
                onPurchaseStateChange( 
                        purchaseState, itemId, quantity, purchaseTime, developerPayload);
            } 
        }); 
    } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post, get
	 
	public static <T> T callInMainThread(Callable<T> call) throws Exception {
		if (isMainThread()) 
			return call.call();
		else { 
			FutureTask<T> task = new FutureTask<T>(call);
			getHandler().post(task);
			return task.get();
		} 
	} 
} 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
    } 
 
    public PicasaService() { 
        super(); 
        mSyncThread.start();
        mSyncHandler = new Handler(mSyncThread.getLooper());
        mSyncHandler.post(new Runnable() {
            public void run() { 
                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            } 
        }); 
    } 
 
    private static PicasaContentProvider getContentProvider(Context context) {
        ContentResolver cr = context.getContentResolver();
        ContentProviderClient client = cr.acquireContentProviderClient(PicasaContentProvider.AUTHORITY);
        return (PicasaContentProvider) client.getLocalContentProvider();
    } 
 
    @Override 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
 
    @Override 
    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        trackLifecycleEvent("onActivityResult"); 
        Handler handler = new Handler();
        handler.post(new Runnable() {
 
            @Override 
            public void run() { 
                onActivityResultUI(requestCode, resultCode, data);
            } 
 
        }); 
    } 
 
    public void onActivityResultUI(int requestCode, int resultCode, Intent data)
    { 
        trackLifecycleEvent("onActivityResultUI"); 
    } 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
/** Executor that runs tasks on Android's main thread. */ 
public final class MainThreadExecutor implements Executor {
  private final Handler handler = new Handler(Looper.getMainLooper());
 
  @Override public void execute(Runnable r) {
    handler.post(r);
  } 
} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post, get, run
     * @param c The Callable to run 
     * @return The result of the callable 
     * @throws ExecutionException c's exception 
     */ 
    public static <T> T runOnUiThreadBlocking(Callable<T> c) throws ExecutionException {
        FutureTask<T> task = new FutureTask<T>(c);
        runOnUiThread(task);
        try { 
            return task.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted waiting for callable", e);
        } 
    } 
 
    /** 
     * Run the supplied FutureTask on the main thread. The method will block only if the current 
     * thread is the main thread. 
     * 
     * @param task The FutureTask to run 
     * @return The queried task (to aid inline construction) 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post, get
 
    public static <T> T callInMainThread(Callable<T> call) throws Exception {
        if (isMainThread()) { 
            return call.call();
        } else { 
            FutureTask<T> task = new FutureTask<T>(call);
            getHandler().post(task);
            return task.get();
        } 
    } 
 
    public static Bitmap takeScreenshot(View view, Bitmap.Config config) {
        int width = view.getWidth();
        int height = view.getHeight();
 
        if (view != null && width > 0 && height > 0) {
            Bitmap bitmap = Bitmap.createBitmap(width, height, config);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            return bitmap;
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: post
      @Override 
      public void run() { 
        final Bitmap bitmap         = getThumbnail(maxWidth, maxHeight);
        final ImageView destination = weakImageView.get();
        if (destination != null && destination.getDrawable() == temporaryDrawable) {
          handler.post(new Runnable() {
            @Override 
            public void run() { 
              setThumbnailOn(destination, bitmap, false);
            } 
          }); 
        } 
      } 
    }); 
  } 
 
  private void setThumbnailOn(ImageView imageView, Bitmap thumbnail, boolean fromMemory) {
    if (fromMemory) {
      imageView.setImageBitmap(thumbnail);
    } else { 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Handler post Questions & Answers:

post Method Overview
Causes the Runnable r to be added to the message queue.
See Code Examples for other Android Handler Methods: