I have an activity which needs to modify the SharedPreferences.
public class AddingEmail extends ListActivity implements OnClickListener{
private String newMail;
private SharedPreferences prefs;
private PreferenceManager prefMan;
private EditText emailAdd;
private EditText emailDel;
private ArrayList<String> prefList;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.addingemail);
Log.d("On Addig EMAIL ACTIVITY","on Create");
String name = "com.example.daemon3_preferences";
prefs = this.getSharedPreferences(name, MODE_PRIVATE);
And this is the PreferenceScreen..
public class PreferencesScreen extends PreferenceFragment{
private final String TAG = "PreferencesScreen";
private Set<String> emails;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "OnCreate");
addPreferencesFromResource(R.xml.prefs);
And I have this error:
java.lang.IllegalArgumentException: File /data/data/com.example.daemon3/shared_prefs/com.example.daemon3_preferences.xml.xml contains a path separator
Why it takes .xml.xml instead of .xml?
Breaking out the comment thread into a formal answer here.
Instead of calling
String name = "com.example.daemon3_preferences";
prefs = this.getSharedPreferences(name, MODE_PRIVATE);
call this:
prefs = PreferenceManager.getDefaultSharedPreferences(this);
PreferenceFragment
saves your settings with the PreferenceManager
so by attempting to open the default preferences with getSharedPreferences
, you might be interfering with the PreferenceManager
which could be causing that particular exception.