3

Does anyone know what I can now use to request data to be sync'd on Android using the BackupManager?

The docs state that the method is now deprecated but don't offer an equivalent/replacement call for that method. I am aware that the sync is performed upon an apps first install but that seems to be it?

I am hoping to use SharedPreferences and the BackupManager to sync Key/Value pairs of data across devices connected to the users account.

1 Answers1

-1
    BackupManager backupManager = (BackupManager) getSystemService(BACKUP_SERVICE);
    RestoreSession restoreSession = backupManager.beginRestoreSession();
    if (0 != restoreSession.getAvailableRestoreSets(new android.app.backup.RestoreObserver() {
        @Override
        public void restoreSetsAvailable(RestoreSet[] result) {
            if (result != null && result.length > 0) {
                if (0 != restoreSession.restoreAll(result[0].token, new android.app.backup.RestoreObserver() {
                    @Override
                    public void restoreFinished(int error) {
                        Log.d(TAG, "succeed to restoreAll");
                    }
                })) {
                    Log.d(TAG, "fail to restoreAll");
                    restoreSession.endRestoreSession();
                }
            } else {
                Log.d(TAG, "restore database is empty");
                restoreSession.endRestoreSession();
            }
        }
    })) {
        Log.d(TAG, "fail to getAvailableRestoreSets");
        restoreSession.endRestoreSession();
    }
Yessy
  • 1,172
  • 1
  • 8
  • 13