Android Backup Service requires a filename to backup shared preferences:
public static final String PREFS = "PrefFile";
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
It is clear what to use if filename is given during preferences creation like
public static final String PREF_FILE_NAME = "PrefFile";
SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
But I use default shared preferences:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
What should I pass as PREFS
value to SharedPreferencesBackupHelper
?
Android Shared Preferences Overview Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. Each SharedPreferences file is managed by the framework and can be private or shared. This page shows you how to use the SharedPreferences APIs to store and retrieve simple values.
SharedPreferences are stored in an xml file in the app data folder, i.e.
private static String getDefaultSharedPreferencesName(Context context) {
return context.getPackageName() + "_preferences";
}
see your package name in AndroidManifest.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With