Package 

Class WorkerHandler


  • 
    public class WorkerHandler
    
                        

    Class holding a background handler. We want them to survive configuration changes if there's still job to do.

    • Method Summary

      Modifier and Type Method Description
      static WorkerHandler get(String name) Gets a possibly cached handler with the given name.
      static WorkerHandler get() Returns a fallback WorkerHandler.
      static void execute(Runnable action) Handy utility to perform an action in a fallback thread.Not to be used for long-running operations since they will blockthe fallback thread.
      void run(Runnable runnable) Post an action on this handler.
      <T> Task<T> run(Callable<T> callable) Post an action on this handler.
      void post(Runnable runnable) Post an action on this handler.
      <T> Task<T> post(Callable<T> callable) Post an action on this handler.
      void post(long delay, Runnable runnable) Post an action on this handler.
      void remove(Runnable runnable) Removes a previously added action from this handler.
      Handler getHandler() Returns the android backing Handler.
      HandlerThread getThread() Returns the android backing HandlerThread.
      Looper getLooper() Returns the android backing Looper.
      Executor getExecutor() Returns an Executor.
      void destroy() Destroys this handler and its thread.
      static void destroyAll() Destroys all handlers, interrupting their work andremoving them from our cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • execute

         static void execute(Runnable action)

        Handy utility to perform an action in a fallback thread.Not to be used for long-running operations since they will blockthe fallback thread.

        Parameters:
        action - the action
      • run

         void run(Runnable runnable)

        Post an action on this handler.

        Parameters:
        runnable - the action
      • run

         <T> Task<T> run(Callable<T> callable)

        Post an action on this handler.

        Parameters:
        callable - the action
      • post

         void post(Runnable runnable)

        Post an action on this handler.

        Parameters:
        runnable - the action
      • post

         <T> Task<T> post(Callable<T> callable)

        Post an action on this handler.

        Parameters:
        callable - the action
      • post

         void post(long delay, Runnable runnable)

        Post an action on this handler.

        Parameters:
        delay - the delay in millis
        runnable - the action
      • remove

         void remove(Runnable runnable)

        Removes a previously added action from this handler.

        Parameters:
        runnable - the action
      • destroy

         void destroy()

        Destroys this handler and its thread. After this method returns, the handlershould be considered unusable.Internal note: this does not remove the thread from our cache, but it doesinterrupt it, so the next get call will remove it.In any case, we only store weak references.

      • destroyAll

         static void destroyAll()

        Destroys all handlers, interrupting their work andremoving them from our cache.