有两种方法来测试 View.onRestoreInstanceState(Parcelable state),一种有效,另一种崩溃
onRestoreInstanceState 可以通过更改屏幕方向和更改模拟器设置 devtools/Development Settings/ max app process 进行测试 - max 设置为 1。 onRestoreInstanceState 适用于屏幕方向,但当最大应用进程设置为 1 并重新启动应用时会崩溃。我使用了 Debug.waitForDebugger();连接最大应用程序进程的调试器,设置为 1。
在视图中,可解析的内容被保存并递归恢复:
恢复:
MyClass(Parcel in) {
boolean boolValues[] = new boolean[2];
in.readBooleanArray(boolValues);
if (boolValues[1])
{
next = in.readParcelable(MyClass.class.getClassLoader());
}
//
//recurse here
}
保存:
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])
{
out.writeParcelable(next,flags);
}
}
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])
{
out.writeParcelable(next,flags);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论