3

I am getting the following error when trying to create a shared preferences file from a service:

"Couldn't create directory for SharedPreferences file /dbdata/databases/dimappers.android.pub/shared_prefs/PubStore2.xml"

I am using a Samsung Galaxy S I9000 to test and I have read else where about problems with this specific phone. However, I swear it was working at some point in a normal activity (though admittedly can't get it to work any more...)

Editor editor = getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).edit();
editor.putString(Constants.SaveDataName, xmlString);
editor.commit();

If I call

String s = getSharedPreferences(Constants.SaveDataName, MODE_PRIVATE).getString(Constants.SaveDataName, "");

Immeditately after calling commit it is able to get it, but if I restart the app it isn't able to find it.

T. Kiley
  • 2,752
  • 21
  • 30
  • This might be nothing, but have you tried other modes than `MODE_PRIVATE`? – Rasive Mar 07 '12 at 15:06
  • The whole thing seems to be a little inconsistent (my favourite...) - seems to work more if I don't use debug mode. It still comes up with the same error message but when I restart the service the data is loaded. I will continue to investigate... – T. Kiley Mar 07 '12 at 16:15
  • If everything goes wrong you could always just use `PreferenceManager.getDefaultSharedPreferences(this)` considering the class is an Activity – Rasive Mar 07 '12 at 16:25

1 Answers1

0

It appeared to be my phone (Samsung Galaxy S I9000), it worked (albeit still showing that error) but running the same code on another phone didn't show the error message.

T. Kiley
  • 2,752
  • 21
  • 30
  • I can confirm this: the same problem occurs in my application only on the I9000 but not on other devices. It's not a crashing error, but the application fails to save its SharedPreferences. – ByteWelder Mar 27 '12 at 10:36
  • Same for me (moreover the file that gave me error was GAnalytics config file). This was happening only with published app. A device reboot fixed the problem. – fillobotto Feb 05 '16 at 22:55