我正在弄清楚什么是处理屏幕旋转的最佳方式。我在这里读了数百个问题/答案,但我很困惑。在不丢失数据的情况下处理屏幕旋转 - Android
如何在重新创建活动之前保存myClass数据,以便我可以保留所有重绘活动而无需另一次无用的初始化?
有没有一种更清洁,更好的方式比parcelable?
我需要处理旋转,因为我想更改横向模式下的布局。
public class MtgoLifecounterActivity extends Activity {
MyClass myClass;
// Called when the activity is first created
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
If (?? first run...myClass == null ?) {
myClass = new MyClass();
} else {
// do other stuff but I need myClass istance with all values.
}
// I want that this is called only first time.
// then in case of rotation of screen, i want to restore the other instance of myClass which
// is full of data.
}
使用'onConfigurationChanged'的东西,请参阅:http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – Nanne 2012-04-12 15:33:49