In my application, when the phone is held in portrait mode the filename can be retrieved.
When I rotate the phone, the same file is being used to get the preferences, but this particular preference comes back blank.
I checked the one function where I write to this preference but it isn't called when the phone is rotated.
So, what could be the cause of a change in the sharedpreferences
by rotating the phone?
Here is the code that I use:
static String retrieveStoredFilename(Context context) {
SharedPreferences myPrefs = context.getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE);
String s = myPrefs.getString(FILENAME, "");
return TextUtils.isEmpty(s) ? (String) null : s;
}
Here is some more code in case it helps. This is from the fragment that is actually messed up by the rotation. In onResume filename
is set to null after rotating, but from then on it is null, even when I rotate back.
@Override
public void onPause() {
super.onPause();
mIV.getBitmap().recycle();
mIV.setImageResource(R.drawable.ic_action_search);
if (myBitMap != null)
myBitMap.recycle();
}
@Override
public void onResume() {
super.onResume();
filename = ControllerFragment.retrieveStoredFilename(getActivity());
getBitmap(filename);
mIV.invalidate();
}
And the two constants are:
public static String FILENAME = "filename";
public static String PREF_NAME = "photobrowser";