Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the file name used by default shared preferences?

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?

like image 942
LA_ Avatar asked Oct 31 '14 12:10

LA_


People also ask

Where is the shared preferences file?

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() .

What are shared preferences?

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.

What format are SharedPreferences stored in on disk?

SharedPreferences are stored in an xml file in the app data folder, i.e.


1 Answers

private static String getDefaultSharedPreferencesName(Context context) {
    return context.getPackageName() + "_preferences";
}

see your package name in AndroidManifest.xml

like image 176
Dmitry Avatar answered Sep 20 '22 04:09

Dmitry