0

I have used syncadapter to periodically send data to the server. I am calling it when the application starts using the following piece of code

ContentResolver.addPeriodicSync(
    mAccount,
    AUTHORITY,
    bundleParams,
    SYNC_INTERVAL);

ContentResolver.setSyncAutomatically(mAccount, AUTHORITY, true);
ContentResolver.setMasterSyncAutomatically(true);

Now I want to change the SYNC_INTERVAL and make aggressive periodic syncs when it enters a certain activity. I wanted to know how do I change the sync time and restore it when it comes out of the activity? I tried removing the periodicsync using removePeriodicSync(...), and then adding a sync with different timer. But the sync still runs at the same time interval as previous one.

Roadblock
  • 2,041
  • 2
  • 24
  • 38

1 Answers1

4

I know this is old, but this question is the first thing that comes up on a Google search for this topic, so I thought I'd add more details.

Just use ContentResolver.addPeriodicSync(). According to the docs:

If there is already another periodic sync scheduled with the account, authority and extras then a new periodic sync won't be added, instead the frequency of the previous one will be updated.

Source: link

Danilo Carvalho
  • 395
  • 2
  • 12