!! Please Help, my users are loosing data due to this, and I don't know what to do.
This only happens on Ice Cream Sandwich, works fine on Jelly Bean, Hoenycomb, what causes this?
Since one of my strings is just a number, would it be better to save it as a float or int??
Weird thing is that, it works fine on my acer a500 tablet, with android 4.0.3, but it doesn't work on the emulator with 4.0.3, I've gotten a complaint from a user with a galaxy s3 on 4.0.4, for him is didn't work either..
I'm saving two strings to Shared Preferences like this:
Thanks
private static final String PREFS_NAME = "com.MY_PACKAGE.MY_APP.MY_WIDGET_PROVIDER_CLASS";
private static final String PREF_PREFIX_KEY = "prefix_";
private static final String PREF_SIZE_PREFIX_KEY = "prefix_";
...
static void saveTitlePref(Context context, int mAppWidgetId, String text) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFS_NAME, 0).edit();
editor.putString(PREF_PREFIX_KEY + mAppWidgetId, text);
editor.commit();
}
static void saveSizePref(Context context, int mAppWidgetId, String size) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFS_NAME, 0).edit();
editor.putString(PREF_SIZE_PREFIX_KEY, size);
editor.commit();
}
static String loadTitlePref(Context context, int mAppWidgetId) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String prefix = prefs.getString(PREF_PREFIX_KEY + mAppWidgetId, null);
// If there is no preference saved, get the default from a resource
if (prefix != null) {
return prefix;
} else {
return context.getString(R.string.appwidget_prefix_default);
}
}
static String loadSizePref(Context context, int mAppWidgetId) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String sizeprefix = prefs.getString(PREF_SIZE_PREFIX_KEY, null);
// If there is no preference saved, get the default from a resource
if (sizeprefix != null) {
return sizeprefix;
} else {
return "24";
}
}
Strings xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="appwidget_prefix_default"></string>
<string name="appwidget_text_format"><xliff:g id="prefix">%1$s</xliff:g></string>
<string name="appwidget_size_format"><xliff:g id="sizeprefix">%s</xliff:g></string>
</resources>