我正在弄清楚什麼是處理屏幕旋轉的最佳方式。我在這裏讀了數百個問題/答案,但我很困惑。在不丟失數據的情況下處理屏幕旋轉 - 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