I've an Activity and a Parcelable class that I want to save on orientation changes. Here is the code in the Activity:
Keeper keeper = ...;
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable("keeper", keeper);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null) {
keeper = savedInstanceState.getParcelable("keeper");
}
}
Here is the code of my Keeper class:
public class Keeper implements Parcelable {
...
private int index;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
Log.e("QQQQQQQ", "writeToParcel");
dest.writeInt(index);
}
private Keeper(Parcel in) {
Log.e("QQQQQQQ", "readfromParcel - Keeper");
index = in.readInt();
}
public static final Parcelable.Creator<Keeper> CREATOR
= new Parcelable.Creator<Keeper>() {
public Keeper createFromParcel(Parcel in) {
return new Keeper(in);
}
public Keeper[] newArray(int size) {
return new Keeper[size];
}
}
I don't see the Logs that are written in writeToParcel and in the Parcel constructor.. I've tried to close the app and simulate low memory so that Android kills the activity and i see the Logs!!! Does anyone know why?