提问者:小点点

当按下后退按钮或关闭应用程序时,回收器查看数据不可见


onSaveInstanceState与onRestoreInstanceState不工作。 每当我按下后退按钮或从应用程序出来时,自定义回收视图的数据是不可见的,直到上传下一个文件。 当我上传时,所有的数据都会返回,因为我已经将其存储在共享首选项中。

OnCreate:

 if (savedInstanceState != null) {
            // Restore value of members from saved state
            savedInstanceState.get(String.valueOf(savedInstanceState));
        }
        else
        {
            //initialize members with default values for a new instance
            setContentView(R.layout.activity_resource);
        }
    @Override
    public void onSaveInstanceState(Bundle outState) {


        super.onSaveInstanceState(outState);
    }

    @Override
    public void onRestoreInstanceState(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onRestoreInstanceState(savedInstanceState, persistentState);
    }

共1个答案

匿名用户

OnSaveInstanceState如果布局中的所有视图都具有ID,则自动存储视图状态。

对于在ListAdapter中还原数据,我建议在ViewModel或至少在Presenter中sroring列表,这取决于您使用的体系结构。