1
我有一個進度條,它從oncreate方法開始。 當我改變屏幕方向爲橫向螺紋重啓和舊線的狀態已經一去不復返了 請給我這個問題在方向變化時重新獲得當前活動狀態android
RelativeLayout layout;
LayoutParams params;
ProgressBar pb;
int i;
Bundle bundle;
Thread t;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// asyn name = new asyn();
// name.execute(10);
bundle = savedInstanceState;
// params=RelativeLayout.
pb = (ProgressBar) findViewById(R.id.progressBar1);
pb.setMax(100);
t = new Thread(ProActivity.this);
t.start();
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
int orientation = display.getOrientation();
switch (orientation) {
case Configuration.ORIENTATION_PORTRAIT:
//
Toast.makeText(ProActivity.this, "portrait", 1000).show();
// pb.setProgress(i);
setContentView(R.layout.landscape);
t = new Thread(ProActivity.this);
t.start();
pb.setProgress(i);
break;
case Configuration.ORIENTATION_LANDSCAPE:
Toast.makeText(ProActivity.this, "Landscape", 1000).show();
break;
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState = bundle;
}
public void run() {
for (i = 0; i < 100; i++) {
pb.setProgress(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
我嘗試了這些方法的任何方法或建議,但它不能恢復活動線程狀態
問候 ribin