I'm developing an Android app which uses a high amout of SharedPreferences. I have several SharedPreferences files and I'm making up to 77 calls to these files throughout my app. Sometimes I'm using :
static final String FileName= "SharedPreferencesFile";
at the beginning of my activities and then :
SharedPreferences settings = getSharedPreferences(FileName, Context.MODE_PRIVATE);
whenever I need to use them. Some other times I'm just refering to the files directly as in:
SharedPreferences settings = getSharedPreferences("SharedPreferencesFile", Context.MODE_PRIVATE);
I'm trying to organize things now so I would like to know about different alternatives to do it. My questions are:
- Should I define a single "SharedPreferencesFile" for all the variables in my app or using multiple files as I'm doing now is ok?
- Should I define all these
String FileName= "SharedPreferencesFile"
in thestrings.xml
from my app resources folder instead of putting them at the beginning of my activities and the just use them asSharedPreferences settings = getSharedPreferences(R.string.SharedPreferencesFile, Context.MODE_PRIVATE);
- Should I create a helper class that handles all shared preferences calls for every activity as suggested in Android Shared Preferences