您可以使用putIntegerArrayList()
来存储数据,并getIntegerArrayList()
检索它。但是,您已将变量声明为List<Integer>
,这不满足putIntegerArrayList()
.
你有两个选择。首先,您可以更改声明变量的方式,使它们显式为ArrayList
s,而不仅仅是List
s:
private ArrayList<Integer> _selectednumber= new ArrayList<>();
private ArrayList<Integer> _points = new ArrayList<>();
private int _hit= 0;
private int _round = 1;
protected void onSaveInstanceState(Bundle out)
{
super.onSaveInstanceState(out);
out.putInt("p_hit", _hit);
out.putInt("p_round", _round );
out.putIntegerArrayList("p_selectednumber", _selectednumber);
out.putIntegerArrayList("p_points", _points);
}
@Override
protected void onRestoreInstanceState(Bundle in)
{
super.onRestoreInstanceState(in);
_hit = in.getInt("p_hit");
_round = in.getInt("p_round");
_selectednumber = in.getIntegerArrayList("p_selectednumber");
_points = in.getIntegerArrayList("p_points");
}
或者,您可以在尝试将它们放入捆绑包时包装您的List
实例:new ArrayList<>()
private List<Integer> _selectednumber= new ArrayList<>();
private List<Integer> _points = new ArrayList<>();
private int _hit= 0;
private int _round = 1;
protected void onSaveInstanceState(Bundle out)
{
super.onSaveInstanceState(out);
out.putInt("p_hit", _hit);
out.putInt("p_round", _round );
out.putIntegerArrayList("p_selectednumber", new ArrayList<>(_selectednumber));
out.putIntegerArrayList("p_points", new ArrayList<>(_points));
}
@Override
protected void onRestoreInstanceState(Bundle in)
{
super.onRestoreInstanceState(in);
_hit = in.getInt("p_hit");
_round = in.getInt("p_round");
_selectednumber = in.getIntegerArrayList("p_selectednumber");
_points = in.getIntegerArrayList("p_points");
}