Article directory
I. Introduction
This article WorkManager
documents the advanced use of - custom configuration and initialization.
2. Initialization
The previous usage will WorkManager
initialize when the program starts. If the program is only used at a certain time WorkManager
, it will cause unnecessary performance loss. So on-demand initialization can be used here.
1. Remove the default initialization configuration
This article only records WorkManager2.6
the way after
a. Remove additional startup
functions
Since the function WorkManager2.6
is integrated by default later startup
, if the function is not used in the application, it can be removed in the following way
<!-- If you want to disable android.startup completely. -->
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove">
</provider>
b. Enter and remove workmanager
function
If you just want to remove WorkManager
the function, you can use the following way
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<!-- If you are using androidx.startup to initialize other components -->
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
3. Custom configuration
After the default configuration is removed, a custom configuration is required. The relevant code examples are as follows:
class MyApplication() : Application(), Configuration.Provider {
override fun getWorkManagerConfiguration() =
Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()
}
This series ends here for the time being, and the rest of the functions will be updated again if they are used in work