我希望我的应用程序支持右手和左手用户的不同布局。因此,在更改了相应的首选项后,我想以与例如方向更改时重新启动相同的方式重新启动活动。
到目前为止我尝试了什么:
1.
Intent intent = getIntent();
finish();
startActivity(intent);
这不会存储和加载保存的实例状态
2.
View cv = findViewById(android.R.id.content);
SparseArray<Parcelable> state = new SparseArray<Parcelable>();
cv.saveHierarchyState(state);
setContentView(desiredCv);
cv = findViewById(android.R.id.content);
cv.restoreHierarchyState(state);
即便如此,很多事情都不是应有的样子。
我认为最终我可以弄清楚如何在不重新启动的情况下正确更改布局,但是以与系统定义的配置更改相同的方式来完成它会容易得多。