-
public class WorkerHandlerClass 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 WorkerHandlerget(@NonNull() String name)Gets a possibly cached handler with the given name. static WorkerHandlerget()Returns a fallback WorkerHandler. static voidexecute(@NonNull() 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. voidrun(@NonNull() Runnable runnable)Post an action on this handler. <T> Task<T>run(@NonNull() Callable<T> callable)Post an action on this handler. voidpost(@NonNull() Runnable runnable)Post an action on this handler. <T> Task<T>post(@NonNull() Callable<T> callable)Post an action on this handler. voidpost(long delay, @NonNull() Runnable runnable)Post an action on this handler. voidremove(@NonNull() Runnable runnable)Removes a previously added action from this handler. HandlergetHandler()Returns the android backing Handler. HandlerThreadgetThread()Returns the android backing HandlerThread. LoopergetLooper()Returns the android backing Looper. ExecutorgetExecutor()Returns an Executor. voiddestroy()Destroys this handler and its thread. static voiddestroyAll()Destroys all handlers, interrupting their work andremoving them from our cache. -
-
Method Detail
-
get
@NonNull() static WorkerHandler get(@NonNull() String name)
Gets a possibly cached handler with the given name.
- Parameters:
name- the handler name
-
get
@NonNull() static WorkerHandler get()
Returns a fallback WorkerHandler.
-
execute
static void execute(@NonNull() 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(@NonNull() Runnable runnable)
Post an action on this handler.
- Parameters:
runnable- the action
-
run
<T> Task<T> run(@NonNull() Callable<T> callable)
Post an action on this handler.
- Parameters:
callable- the action
-
post
void post(@NonNull() Runnable runnable)
Post an action on this handler.
- Parameters:
runnable- the action
-
post
<T> Task<T> post(@NonNull() Callable<T> callable)
Post an action on this handler.
- Parameters:
callable- the action
-
post
void post(long delay, @NonNull() Runnable runnable)
Post an action on this handler.
- Parameters:
delay- the delay in millisrunnable- the action
-
remove
void remove(@NonNull() Runnable runnable)
Removes a previously added action from this handler.
- Parameters:
runnable- the action
-
getHandler
@NonNull() Handler getHandler()
Returns the android backing Handler.
-
getThread
@NonNull() HandlerThread getThread()
Returns the android backing HandlerThread.
-
getExecutor
@NonNull() Executor getExecutor()
Returns an Executor.
-
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.
-
-
-
-