WorkerFactory
public
abstract
class
WorkerFactory
extends Object
java.lang.Object
|
↳ |
androidx.work.WorkerFactory
|
A factory object that creates ListenableWorker
instances. The factory is invoked every
time a work runs. You can override the default implementation of this factory by manually
initializing WorkManager
(see WorkManager.initialize(Context, Configuration)
and
specifying a new WorkerFactory in Configuration.Builder.setWorkerFactory(WorkerFactory)
.
Summary
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
WorkerFactory
public WorkerFactory ()
Public methods
createWorker
public abstract ListenableWorker createWorker (Context appContext,
String workerClassName,
WorkerParameters workerParameters)
Override this method to implement your custom worker-creation logic. Use
Configuration.Builder.setWorkerFactory(WorkerFactory)
to use your custom class.
Throwing an
Exception
here will crash the application. If a
WorkerFactory
is unable to create an instance of the
ListenableWorker
, it should return
null
so it can delegate to the default
WorkerFactory
.
Returns a new instance of the specified
workerClassName
given the arguments. The
returned worker must be a newly-created instance and must not have been previously returned
or invoked by WorkManager. Otherwise, WorkManager will throw an
IllegalStateException
.
Parameters |
appContext |
Context : The application context |
workerClassName |
String : The class name of the worker to create |
workerParameters |
WorkerParameters : Parameters for worker initialization |