1

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);
    }

}       
4

0 回答 0