Challenge


#1

Hey guys,

Trying to do the first part of the challenge. With the help of google I thought I had figured it out. So at the beginning and in the constructor I put a

public BoxDrawingView(Context context, AttributeSet attrs) { super(context, attrs); super.setSaveEnabled(true);

and then at the the very end I put

[code]@Override
protected Parcelable onSaveInstanceState() {

    Bundle bundle = new Bundle();
    bundle.putParcelable("instanceState", super.onSaveInstanceState());
    Log.i(TAG, "saved instance state");

    return bundle;
  }

  @Override
  protected void onRestoreInstanceState(Parcelable state) {

    if (state instanceof Bundle) {
      Bundle bundle = (Bundle) state;
      super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
      Log.i(TAG, "returning instance state");
      return;
    }

    super.onRestoreInstanceState(state);
  }

[/code]

However, neither the Logs are being detected in debug so it seems that neither onSaveInstanceState nor onRestoreInstanceState are being called. So I was wondering what I was missing here.


#2

setSaveEnabled(true) isn’t necessary. The missing piece of the puzzle here is that your view must have an id to save instance state. Otherwise, Android has no way to keep track of which view the instance state belongs to.

I’ll add a note to the errata.