当屏幕旋转时,我也尝试恢复字符串值,但它始终为空。
public class Main_screen extends Activity {
TextView t;
String path, ext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
t = (TextView) findViewById(R.id.textView2);
if (savedInstanceState != null){
path = savedInstanceState.getString(path);
ext = savedInstanceState.getString(ext);
t.setText(getString(R.string.selected) + "\n" + path + "\n\n" + getString(R.string.unpr_new) + "\n" + path + ext);
}
}
当我旋转设备时,路径和分机为空。我需要手动保存字符串吗?还是在已保存实例中旋转时自动保存?