Okay, so query for you is that from latest library version of WorkManager (dependency : android.arch.work:work-runtime:1.0.0-alpha09),
Theres's constructor changed from
Worker()
to
Worker(@NonNull Context appContext, @NonNull WorkerParameters workerParams).
Which means that default constructor is now no longer useful (Deprecated, Marked as it should be removed on future versions) & we're now on parameterized constructor.
Now, if you've noticed that when we use our Worker, we're not directly creating new object of it, instead we do something like this,
OneTimeWorkRequest.from(FooWorker.class) // We pass Class<?> obj of our worker here, or in PeriodicWorkRequest-it's the same
(Passing class Object of our Worker to our WorkRequest)
this means that WorkParameters are something that is provided by DefaultWorkerFactory internally. So you don't have to worry about it because, we're not going to create new object of Worker by ourself, unless you want any customized setup (Which is now possible by this version & it's good).
Also, from latest API changes on September 19, 2018
- You can now create your own
Worker instances at runtime by specifying a WorkerFactory as part of the WorkManager.Configuration.
The fallback factory is DefaultWorkerFactory, which matches behavior
of previous versions of WorkManager.
- The default constructors for
Worker and NonBlockingWorker are now marked as deprecated. Please use the new constructor (Worker(Context, WorkerParameters)) and call super(Context, WorkerParameters); future
versions of WorkManager will remove the default constructor.
So now, it's the reason this question is all about, that what if i want to create WorkerParameters?
Answer is that before you can create WorkerParameters, you'll need to override default behaviour of WorkManager library and provide your own customized WorkManager.Configuration & by that creating your own Worker, at Runtime by providing WorkerParameters to it. (This is the case where we need to provide WorkerParameters, you might not wanna do that if you're just using WorkManager functionalities out of the box)
There's GoogleCodeLab's example which beautifully explains WorkManager (You can see here how it's done with new constructor).
Conclusion:
Let's say you have got a Worker class called FooWorker, then your code will look like this:
public class FooWorker extends Worker {
public FooWorker(
@NonNull Context appContext,
@NonNull WorkerParameters workerParams) {
super(appContext, workerParams);
}
private static final String TAG = FooWorker.class.getSimpleName();
@NonNull
@Override
public Worker.Result doWork() {
// Do some work & return appropriate result.
}
}
and initialize like this
//Init WorkManager
private WorkManager mWorkManager;
mWorkManager = WorkManager.getInstance();
// Enqueue our work to manager
mWorkManager.enqueue(OneTimeWorkRequest.from(FooWorker.class)); // Here, we're not creating new FooWorker(); & we don't need to worry about `WorkerParameters` for now.
So there's no case to access/create constructor/object of WorkerParamters.
I hope this answer satisfies your question and helps.