diff --git a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java index 0a1f9d4d..0e044041 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java +++ b/SWADroid/src/es/ugr/swad/swadroid/SWADMain.java @@ -278,8 +278,8 @@ public class SWADMain extends MenuExpandableListActivity { lastVersion = prefs.getLastVersion(); currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; dbHelper.initializeDB(); - //lastVersion = 55; - //currentVersion = 56; + //lastVersion = 56; + //currentVersion = 57; //If this is the first run, show configuration dialog if (lastVersion == 0) { @@ -319,6 +319,7 @@ public class SWADMain extends MenuExpandableListActivity { if(Preferences.isSyncEnabled()) { activity = new Intent(getBaseContext(), AccountAuthenticator.class); startActivity(activity); + SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, this); SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(prefs.getSyncTime()), this); } diff --git a/SWADroid/src/es/ugr/swad/swadroid/sync/SyncUtils.java b/SWADroid/src/es/ugr/swad/swadroid/sync/SyncUtils.java index 75bf9cc3..d46154ac 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/sync/SyncUtils.java +++ b/SWADroid/src/es/ugr/swad/swadroid/sync/SyncUtils.java @@ -59,17 +59,17 @@ public class SyncUtils { } public static void removePeriodicSync(String authority, Bundle extras, Context context) { - if (android.os.Build.VERSION.SDK_INT >= 8) { - AccountManager am = AccountManager.get(context); - Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE); + if (android.os.Build.VERSION.SDK_INT < 8) { + AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + PendingIntent operation = PeriodicSyncReceiver.createPendingIntent(context, authority, extras); + manager.cancel(operation); + } else { + AccountManager am = AccountManager.get(context); + Account[] accounts = am.getAccountsByType(Constants.ACCOUNT_TYPE); - for (Account a : accounts) { - ContentResolver.removePeriodicSync(a, authority, extras); - } + for (Account a : accounts) { + ContentResolver.removePeriodicSync(a, authority, extras); + } } - - AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - PendingIntent operation = PeriodicSyncReceiver.createPendingIntent(context, authority, extras); - manager.cancel(operation); } }