WorkManager.getInstance() is Deprecated in version 2.1.0
dependency :
implementation 'androidx.work:work-runtime:2.1.0'
What are the changes in this method or any other ways?
WorkManager.getInstance() is Deprecated in version 2.1.0
dependency :
implementation 'androidx.work:work-runtime:2.1.0'
What are the changes in this method or any other ways?
I found the solution on documentation as follow:
This method is deprecated.
Call getInstance(Context) instead.
Where Context is used for on-demand initialization.
WorkManager v2.1 introduces a new way to customize its configuration. While with the previous version it was necessary to create a new configuration and initialize WorkManager during the app startup, v2.1 adds a new "on demand" initialization.
This means that WorkManager is initialized (with the default or the custom) initialization the first time that the app calls the getInstance(Context)
method.
The Context
in this case is used to retrieve the application object and see if it implements the Configuration.Provider
interface.
More information are available in WorkManager's documentation on custom configuration.
This change is documented in WorkManager's release notes (this was introduced in WorkManager v2.1-alpha01) and it's explained there why it's better to use the new getInstance(Context)
method even if you're not using on demand initialization.
Note : Whenever you change or update dependency version, please go through the release notes
According to document, you must use this way:
val workManager = WorkManager.getInstance(applicationContext)
© 2022 - 2024 — McMap. All rights reserved.