SharedPreferences example

SharedPreferences example


import android.content.SharedPreferences;

write:
SharedPreferences sp = getSharedPreferences("PREF_NAME", MODE_WORLD_WRITEABLE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("key", enable);
editor.commit();

read:
Context context = this.createPackageContext("***.***.sharepreferencewrite", Context.CONTEXT_IGNORE_SECURITY);
(from another application)
SharedPreferences sp = context.getSharedPreferences("PREF_NAME", MODE_PRIVATE); 
boolean enaled = sp.getBoolean("key", false);

data store:

/data/data/package_name/shared_prefs

你可能感兴趣的:(SharedPreferences example)