So, in each you should be using the same context and not just "this
".
private Context context;
public void onCreate(){
super.onCreate();
context = getApplicationContext();
}
public static Context getAppContext() {
return context;
}
You can make this context accessible by other classes that do not have a type (just function holders).
Then, in your use of Shared Prefs :
final SharedPreferences prefList = context.getSharedPreferences(
Constants.PREFERENCE_NAME, Context.MODE_PRIVATE);
If everyone is using getApplicationContext()
then they will be able to talk to one another as they are all using the same Context
. I would always suggest that you use Context.MODE_PRIVATE
unless you need external applications to be able to grab information from those SharedPreferences
.