Jaichander
Jaichander

Reputation: 832

Android - Timer not running in perodic intervals when app is in locked or sleep state

In my android project I have periodic task to update API for every 60 seconds for that i am using TimerTask everything is working fine when app is in background or foreground when app is in locked state or sleep state timer milliseconds is lagging every minute, such as first api timing is 10.00.00 second api timing is 10.01.05 for every count milliseconds is getting increased

I have tried Work Manager but my perodic interval is 60 Sec,I need an answer which runs perodic Jobs for every 60 Sec without any time lag

I refered this code https://github.com/codexpedia/android_sync_adapter its working fine I have one more issue in SyncAdapter, Some devices Sync Adapter skips Eg: - If I set 60 Sec interval it skips 1 min for every 5 mins could you help me

If app is in doze mode any other solution which works for 7 & 8 api version

Upvotes: 1

Views: 506

Answers (1)

Aniruddha K.M
Aniruddha K.M

Reputation: 7511

Since your requirement is to sync the data between app and server you can use the native feature of Android called SyncAdapter, this will sync the data either way based on a time interval. You can read about it here in the docs. I would suggest this approach instead of TimerTask.

Upvotes: 1

Related Questions