I'm using WorkManager by calling WorkManager.enqueueUniqueWork(String, ExistingWorkPolicy, OneTimeWorkRequest)
, I examined on the db on disk androix.work.workdb
and noticed in the WorkName
table there is an entry for each job I started. They aren't removed after the work completed. Is this normal? Will they automatically be cleared? When and by whom? (the system or WorkManager?)
This is normal. WorkManager keeps finished jobs in its database so that you can continue to query for its WorkInfo
via getWorkInfosForUniqueWorkLiveData()
or other methods that give you the stats back (a fact pointed out by the keepResultsForAtLeast()
documentation). If this was not the case, you'd never be able to find out that your job has succeeded, failed, or been cancelled.
As per the pruneWork()
documentation:
You do not normally need to call this method - WorkManager takes care to auto-prune its work after a sane period of time
Where 'a sane period of time', according to the source code is currently set to 1 day (previously 7 days).