In my code I created a card class; I show a bunch of cards later in a gridview.
On screen orientation change I am loosing all the cards; with my previous question I was pointed in the right direction.
Now, what I have found in Android documentation and here in StackO is that
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(...);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
some_int_var = savedInstanceState.getInt(...);
super.onRestoreInstanceState(savedInstanceState);
}
Now, I do that OK, since the Bundle object has several methods like putString, Char, etc. The primitives plus string that is. But what about my cards? they are Card objects in a vector thus I can’t use any of those methods.
How can I restore that vector WITHOUT using onRetainNonConfigurationInstance nor preventing the activity reset? In Android documentation it is advice to do this if there’s heavy data to restart but that’s not my case.
For your own objects you can use
putParcelable()To make your object parcelable you should implement
Parcelableand follow the following example to implement it.http://prasanta-paul.blogspot.nl/2010/06/android-parcelable-example.html
So: