Android manage configuration changes(state) in custom view
<p>This is follow up to: <a href="http://stackoverflow.com/questions/7179706/android-local-variable-gets-lost-when-using-camera-intent">Android local variable get&#39;s lost when using camera intent</a></p>

<p>Proper way to do it is to handle onSaveInstanceState and onRestoreInstanceState like shown here:
<a href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/CompoundButton.java" rel="nofollow">http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/CompoundButton.java</a></p>

<p>Here is my code:</p>

<pre><code>static class SavedState extends BaseSavedState
    {
        private String requestedFileName;
        private UUID[] mImages = new UUID[4];

        SavedState(Parcelable superState)
        {
          super(superState);
        }

        private SavedState(Parcel in)
        {
          super(in);
        }

        @Override
        public void writeToParcel(Parcel out, int flags)
        {
          super.writeToParcel(out, flags);
        }

        //required field that makes Parcelables from a Parcel
        public static final Parcelable.Creator&lt;SavedState&gt; CREATOR =
            new Parcelable.Creator&lt;SavedState&gt;()
            {
              public SavedState createFromParcel(Parcel in)
              {
                return new SavedState(in);
              }
              public SavedState[] newArray(int size)
              {
                return new SavedState[size];
              }
        };

    }

    @Override
    public Parcelable onSaveInstanceState()
    {
        //begin boilerplate code that allows parent classes to save state
        Parcelable superState = super.onSaveInstanceState();

        SavedState ss = new SavedState(superState);
        //end

        ss.requestedFileName = this.requestedFileName;
        ss.mImages = this.mImages;

        return ss;
    }

    @Override
    public void onRestoreInstanceState(Parcelable state)
    {
        //begin boilerplate code so parent classes can restore state
        if(!(state instanceof SavedState))
        {
            super.onRestoreInstanceState(state);
            return;
        }

        SavedState ss = (SavedState)state;
        super.onRestoreInstanceState(ss.getSuperState());
        //end

        this.requestedFileName = ss.requestedFileName;
        this.mImages = ss.mImages;

        RestoreImageState();
    }
</code></pre>

<p>Now to my question. This code seems to work properly and it handles all state changes without a problem. HOWEVER, if you look at <strong>SavedState.writeToParcel</strong> and <strong>SavedState.SavedState</strong> you will notice that I do not store my variables there. Do I have to? Why? Problem is that I understand how to wrteToParcel and my data types match. But reading out of parcel not so clear with complex types. And in my tests it wasn't called. </p>

<p>EDIT:</p>

<p>Does this look correct for save/retreive order?</p>

<pre><code>private SavedState(Parcel in)
        {
          super(in);
          this.mName = in.readString();
          this.mIndex = in.readInt();
          this.mApplicableDamages = (String[])in.readValue(null);
          this.mSelectedDamages = (boolean[])in.readValue(null);                            
        }

        @Override
        public void writeToParcel(Parcel out, int flags)
        {
          super.writeToParcel(out, flags);
          out.writeString(this.mName);
          out.writeInt(this.mIndex);
          out.writeArray(this.mApplicableDamages);
          out.writeBooleanArray(this.mSelectedDamages);
        }
</code></pre>
