不幸的是(据我所知)我正在尝试传递(对象)数组,可序列化 bundle 不适用于自定义对象。
我有类(class)座位:
public class seat{
boolean state;
int Seatb;
}
这是第一个 Activity 的代码:
seat [][] arrseat=new seat[20][20];
Intent intent = new Intent(this, MainActivity2.class);
intent.putExtra("data", arrseat);
startActivity(intent);
第二个 Activity :
seat [][] obseat=new seat[20][20];
Intent intent = getIntent();
obseat=intent.?
我找不到从 intent 获取数组的方法
最佳答案
数组是可序列化的,所以你可以使用putSerializable。 投入值(value)
Intent i = new Intent(this, AnotherClass.class);
Bundle b = new Bundle();
b.putSerializable("arr", seat);
i.putExtras(b);
获得值(value)
seat[][] arrseat = (seat[][]) bundle.getSerializable("arr");
关于android - 将二维对象数组传递给另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038633/