What is the difference between getPreferences and getSharedPreferences in android ? To secure preference file from other activities in an android application, which one to use? getpreferences() or getsharedpreferences()?
Use getPreferences(), but its not guaranteed to be protected as it will be stored with the name of Activity.
use getSharedPreferences(), but its not guaranteed to be protected as it will be stored with the name of Activity.
getPreferences(0) - will open or create a preference file with out giving a name specifically. By default preference file name will be the current Activity name. if some one knows this, any once can access getPreference() file using that activity name.
getSharedPreferences("name",0) - will open or create a preference file with the given name. If you want to create a preference file with a specific name then use this function. If you want multiple preference files for you activity, then also you can use this function.
Note: preferences file will be with .xml extension stored in data/data/preferences folder.
Back To Top