Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last updated time at from WorkManager's Work/WorkInfo

Is there any way to get finished or successful work timestamp?

WorkManager.getInstance().getWorkInfosByTagLiveData(groupId) this code gives WorkInfo.

I'm sure that WorkManager has timestamps to manage Work, but how to obtain it?

like image 478
Kyryl Zotov Avatar asked Sep 11 '25 10:09

Kyryl Zotov


1 Answers

I'm inspecting androidx.work.workdb file which is located at /data/data/com.example/databases. As of WorkManager 2.2.0 here're the columns that are present in the WorkSpec table:

  • id (e.g. dbe0dcd0-ab76-4c1e-a963-be2135f41c3c)
  • state (e.g. 2)
  • worker_class_name (e.g. com.example.MyWorker)
  • input_merger_class_name (mostly null, but also androidx.work.OverwritingInputMerger)
  • input
  • output
  • initial_delay (e.g. 300000)
  • interval_duration (e.g. 900000)
  • flex_duration (e.g. 900000)
  • run_attempt_count (e.g. 1)
  • backoff_policy (e.g. 0)
  • backoff_delay_duration (e.g. 30000)
  • period_start_time (e.g. 1578901635581)
  • num_retention_duration (e.g. 0)
  • schedule_requested_at (e.g. 1578901635601)
  • required_network_type (e.g. 1)
  • requires_charging (e.g. 0)
  • requires_device_idle (e.g. 0)
  • requires_battery_not_low (e.g. 1)
  • requires_storage_not_low (e.g. 0)
  • trigger_content_update_delay (e.g. -1)
  • trigger_max_content_delay (e.g. -1)
  • content_uri_triggers

As can be deduced, there doesn't exist a field, which will reflect the timestamp when a particular work has been completed, because as per my understanding WorkManager doesn't need that field.

Hence, your only option is upon work's successful completion manually saving the timestamp using shared prefs or another SQLite table.

like image 106
azizbekian Avatar answered Sep 13 '25 23:09

azizbekian