I want to download the server DB content to my local SQLite in an android app when the first-time app runs. After that, I want to sync periodically(say every day when the app opens) with the server. As the developer doc says I can schedule any background work with new android jetpack API WorkManager. If anyone has done this before please mention how?
Asked
Active
Viewed 1,289 times
0
-
Maybe you should start by reading the work manager documentation. https://developer.android.com/topic/libraries/architecture/workmanager/ I think the doc will give the right answers or approach – Paul Okeke Sep 11 '18 at 23:44
-
also this answer may help to schedule a work at given (flex) time https://stackoverflow.com/a/54394957/2895571 – pavle Dec 02 '19 at 08:34
1 Answers
1
Suppose you want to schedule periodic update to fire data upload every day at 2am. What you need to do is when first time application runs, calculate initial delay in milliseconds which will be (initialDelay = timestamp at tomorrow 2am - currenttimestamp)
Now schedule a onTimeWorkRequest with that inital delay. so at 2am this work will be fired now inside that work schedule a periodic work which will be having actual uploading logic request with repeat interval 24 hours. From there this periodic request will get at 2am everyday. Use "networkConnected" constraint with periodic request.

Ritzor
- 665
- 7
- 26