Something thats not covered on the Android site is when in, I guess, your Main Activities lifecycle you should call your SharedPreferencesBackupHelper() / BackupAgent. I'm guessing the Agent needs the App to still be running to complete, so onDestroy() is probably too late, not sure about onStop(), should you simply override onSaveInstanceState()? Is there any best practice around?
Asked
Active
Viewed 138 times
1 Answers
0
You never call your backup agent directly.
What you do is call dataChanged() on a BackupManager object when your app calls commit() or apply() on its shared preferences. This lets the OS know that your app needs to be backed up again. At some point in the future (normally within an hour or so), the OS will fire up your app's BackupAgent and call into it as you expect. This will happen even if your app has been stopped in the meantime -- it's not related to the activity or service lifecycle.

ctate
- 1,379
- 10
- 11