Challenge: Rotations

Figure out how to persist your boxes across orientation changes from within your View. This can be done with the following View methods:

 ​ ​ ​ ​p​r​o​t​e​c​t​e​d​ ​P​a​r​c​e​l​a​b​l​e​ ​o​n​S​a​v​e​I​n​s​t​a​n​c​e​S​t​a​t​e​(​)​
 ​ ​ ​ ​p​r​o​t​e​c​t​e​d​ ​v​o​i​d​ ​o​n​R​e​s​t​o​r​e​I​n​s​t​a​n​c​e​S​t​a​t​e​(​P​a​r​c​e​l​a​b​l​e​ ​s​t​a​t​e​)​

These methods do not work like Activity and Fragment’s onSaveInstanceState(Bundle). Instead of taking in a Bundle, they return and process an object that implements the Parcelable interface. We recommend using a Bundle as the Parcelable instead of implementing a Parcelable class yourself. (Implementing the Parcelable interface is complicated. It is better to avoid doing so when possible.) ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.