I don’t understand the concect of shared preference in android. Shared prefrerence is accessbile by the ather application on the smartphone?
If i use this class for save preference:
public class ImpostazioniActivity extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.impostazioni);
} }
Anda after in other activity i use:
SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(getContext());
if(preference.getString("username","").length() == 0 || preference.getString("password","").length() == 0)
return false;
else
return true;
It’s ok? I’m sure thet the information are accesible only in my application?
Thanks
Quote:
So you should use
getSharedPreferences(PREFS_FILENAME, Context.MODE_PRIVATE)where PREFS_FILENAME is the file you want you application to use andContext.MODE_PRIVATEis a file creation mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).EDIT: I looked at your code, if you intent to store any sensitive user infromation (like password) you must encrypt it first! Take a look at this ObscuredSharedPreferences implementation. It will enable you to encrypt/decrypt your data in SharedPreferences.