I am using sync adapter in my app. The app should perform a sync at every 3 hours. This can be done with ContentResolver.addPeriodicSync
. But, prior to that, with every sync request I need to send the access token of the user. The token's expiry time is of 2 hours. So, before any sync request it needs to have a valid access token. If the access token have expired, a fresh token needs to be updated for the user.
One solution, I came up is to set a repeating alarm with using AlarmManager
. When the alarm triggers, an IntentService
will startup. and refreshes the access token for user. After new token is obtained, the sync request will be sent to the SyncAdapter
, using ContentResolver.requestSync
. I am not sure if this is a good way to do or any other efficient approach is available.