简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM