I use Default Shared Preferences to save some data in them.
I have created a class to handle all this :
public class PreferencesHandler {
private Context mContext;
public PreferencesHandler (Context context) {
this.mContext = context;
}
public void setBoolean(String name, boolean value) {
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putBoolean(name, value).commit();
}
public void setInt(String name, int value) {
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putInt(name, value).commit();
}
public boolean getBoolean(String name, boolean defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean(name, defaultValue);
}
public int getInt(String name, int defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(mContext).getInt(
name, defaultValue);
}
}
How you see I created a Handler class for easier access.
Also I have a Methods class where all my methods are stored.
And in that class I have a method which uses this handler class :
public class Methods {
private Context mContext;
public Methods(Context context) {
this.mContext = context;
}
public void process (PreferencesHandler pref, String prefName, int default) {
int mInt= pref.getInt(prefName, default);
//The rest doesn't matters
}
}
I call this method in my activity class.
With the debugger I found out that the error is in the Handler, when it executes the return line, it opens the PreferenceManager.class with the text "Source not found".
It says that the JAR file android.jar has no source attachment.
What should I do to fix this?