there are two way to test View.onRestoreInstanceState(Parcelable state), one works the other crashes
onRestoreInstanceState can be tested by changing screen orientation, and by changing the emulator settings devtools/Development Settings/ max app process - with max set to one. onRestoreInstanceState works with the screen orientation but crashes with max app process set to 1 and restarting the app. I used Debug.waitForDebugger(); to connect the debugger for the max app process set to 1.
In the view a parsable is saved restored recurivly:
restoring:
MyClass(Parcel in) {
boolean boolValues[] = new boolean[2];
in.readBooleanArray(boolValues);
if (boolValues[1])
{
next = in.readParcelable(MyClass.class.getClassLoader());
}
//
//recurse here
}
saving:
public void writeToParcel(Parcel out, int flags) {
// TODO Auto-generated method stub
boolean boolValues[] = new boolean[2];
boolValues[0] = aValue;
boolValues[1] = next != null;
out.writeBooleanArray(boolValues);
if (boolValues[1开发者_如何学Go])
{
out.writeParcelable(next,flags);
}
}
精彩评论