I'm basically trying to save an array of Bitmaps between states.
My fragment's onSaveInstanceState:
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelableArray(SELECTED_IMAGES_ARRAY_BUNDLE, galleryAdapter.getImageBitmaps());
}
And in it's onCreateView I retrieve the array as so:
savedInstanceState.setClassLoader(Bitmap.class.getClassLoader());
Bitmap[] savedSelectedImages = (Bitmap[]) savedInstanceState.getParcelableArray(SELECTED_IMAGES_ARRAY_BUNDLE);
This WORKS regularly, EXCEPT when the Android OS does some memory management, kills off my process if it's running in the background, and later tries to restore it when I come back to it.
This is the error I get:
AndroidRuntime(4985): Caused by: java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to android.graphics.Bitmap[]
I thought it was something to do with not properly setting the classLoader, but I tried everything and can't seem to get it to work
You can do something like this.Where p is your parcelable list. And finally convert list of bitmaps back to an array.