Currently I'm writing android application, whose main functions are just fingerpainting on screen. The main problem is how to store application's data model. What would be the best practice? Currently data model looks like this:
public class BoardModel {
public Bitmap mBoard;
public int mLineWidth = 1;
public int mForegroundColor = Color.GREEN;
public int mBackgroundColor = Color.BLACK;
}
This class is instantiated when onCreate method of main activity is called. During it's lifecycle activity can be destroyed. For example it happens when user changes the device orientation from portrait to landscape. So to store my model I'm overriding onSaveInstanceState like this:
protected void onSaveInstanceState(Bundle outState) {
outState.putParcelable(KEY_MODEL, mModel);
}
and modified onCreate method like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (savedInstanceState == null) {
mModel = new BoardModelParcelable();
} else {
mModel = savedInstanceState.getParcelable(KEY_MODEL);
}
}
Also I added following class to implement Parcelable interface
public class BoardModelParcelable extends BoardModel implements Parcelable{
....
}
The problem is that when I add any data to my model I have to modify BoardModelParcelable to store it. For example I'm planning to add class that describes the instrument, that is used to draw something. In this case I need to create another class for instrument, that implements Parcelable interface? Or should I perform storing instrument data in BoardModelParcelable? Looks like I must implement too much parcelable objects. Any Ideas how to store my model data without creating saving code this much?