你需要重写的onSaveInstanceState(捆绑savedInstanceState)和写要更改的捆绑参数这样的应用程序的状态值:
你可以这样
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("myBoolean", false);
savedInstanceState.putDouble("myDouble", 1.121);
savedInstanceState.putInt("myInt", 0);
savedInstanceState.putString("myString", "Your String");
// etc.
}
保存每个变量的实例并改变你可以这样回顾
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
boolean myBoolean = savedInstanceState.getBoolean("myBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
int myInt = savedInstanceState.getInt("myInt");
String myString = savedInstanceState.getString("myString");
}
希望这会帮助你.cheers!
UPDATE:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
p.set("orientation", "portrait");
p.set("rotation",90);
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "landscape");
p.set("rotation", 90);
}
,并设置属性是这样的:
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
camera.setParameters(parameters);
阅读[this](https://developer.android.com/guide/topics/resources/runtime-changes.html)了解如何处理Android中的方向更改。 – NonCreature0714