Scheduled sync adapter runs every 30 seconds

I use synchronization adapters in my application to periodically synchronize changes with the server. No matter what value I set in pollFrequency, synchronization is done every 30 seconds.

I checked on the forum and tried the changes suggested in the answers and pass "false" as the syncToNetwork parameter when I raise the notifyChange to ContentResolver.

Continuing the detailed training, I came across this difference.

On the Google developer’s site → training section Training on synchronization adapters I can see that the addPeriodicSync → pollFrequency parameter is passed in milliseconds

public class MainActivity extends FragmentActivity {
...
// Constants
// Content provider authority
public static final String AUTHORITY = "com.example.android.datasync.provider";

// Account
public static final String ACCOUNT = "default_account";

// Sync interval constants
public static final long MILLISECONDS_PER_SECOND = 1000L;
public static final long SECONDS_PER_MINUTE = 60L;
public static final long SYNC_INTERVAL_IN_MINUTES = 60L;

//This is the line I'm referring to
public static final long SYNC_INTERVAL = SYNC_INTERVAL_IN_MINUTES * 
                                         SECONDS_PER_MINUTE *
                                         MILLISECONDS_PER_SECOND;

// Global variables
// A content resolver for accessing the provider
ContentResolver mResolver;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    // Get the content resolver for your app
    mResolver = getContentResolver();
    /*
     * Turn on periodic syncing
     */
    ContentResolver.addPeriodicSync(
            ACCOUNT,
            AUTHORITY,
            null,
            SYNC_INTERVAL);
    ...
    }
    ...
}

API API pollFrequency . ? , ? .

+4
2

       ContentResolver.setMasterSyncAutomatically(true), . setSyncAutomatically .

.

+1

SYNC_INTERVAL , .

addPeriodicSync() :

pollFrequency, .

+1

Source: https://habr.com/ru/post/1524786/


All Articles