A Fragment without its own User Interface

This app demonstrates a non-deprecated way of keeping the first Etch A Sketch’s drawing intact when the orientation changes.

The Path lives inside a RetainedFragment in EtchView.java. The RetainedFragment holds the Path and provides a getter, and does very little else. But the RetainedFragment is potentially capable of outliving the Activity that created it. In fact, it will outlive the Activity, thanks to the call to setRetainInstance, and will be read by the next instantiation of the Activity. The FragmentManager keeps the fragment alive in between incarnations of the Activity.

Source code in Etch.zip

  1. EtchActivity.java
  2. EtchView.java
  3. main.xml: unused.
  4. AndroidManifest.xml: untouched.