This is the
Etch A Sketch app we saw
here,
but it no longer erases the drawing when we change the orientation.
The methods
onRetainNonConfigurationInstance
and
getLastNonConfigurationInstance
of class
Activity
are deprecated since the introduction of
Fragment
s
in Android 3.0 (SDK 11),
,
but I still have to use them because my Android phone only has SDK version 8.
See
Retaining
an Object During a Configuration Change.
We can use this machinery to save and restore a
Path
,
because a
Path
does not contain a
Context
.
We could not have used this machinery to save and restore a
View
.
To erase the drawing,
you will now have to go to the Settings app and stop the Etch A Sketch app.
Settings →
Applications →
Manage applications →
Etch →
Force stop
EtchActivity.java
:
the
EtchView
is now a field.EtchView.java
:
the constructor now takes an extra argument.main.xml
: ignored.AndroidManifest.xml
:
untouched.