I'm trying to pass array of (objects) unfortunately (as far as i know) serializable bundle will not work with custom objects.
我试图传递(对象)数组(据我所知)可序列化的包不能用于自定义对象。
I have class seat:
我有座位:
public class seat{
boolean state;
int Seatb;
}
And here is a code from the first activity:
这是第一个活动的代码:
seat [][] arrseat=new seat[20][20];
Intent intent = new Intent(this, MainActivity2.class);
intent.putExtra("data", arrseat);
startActivity(intent);
Second activity:
seat [][] obseat=new seat[20][20];
Intent intent = getIntent();
obseat=intent.?
I could not find a way to get the array from intent
我找不到从意图中获取数组的方法
1 个解决方案
#1
Arrays are serializable, So you can use putSerializable. to put value
数组是可序列化的,因此您可以使用putSerializable。投入价值
Intent i = new Intent(this, AnotherClass.class);
Bundle b = new Bundle();
b.putSerializable("arr", seat);
i.putExtras(b);
to get value
获得价值
seat[][] arrseat = (seat[][]) bundle.getSerializable("arr");
also it is a similar problem here
这也是一个类似的问题
#1
Arrays are serializable, So you can use putSerializable. to put value
数组是可序列化的,因此您可以使用putSerializable。投入价值
Intent i = new Intent(this, AnotherClass.class);
Bundle b = new Bundle();
b.putSerializable("arr", seat);
i.putExtras(b);
to get value
获得价值
seat[][] arrseat = (seat[][]) bundle.getSerializable("arr");
also it is a similar problem here
这也是一个类似的问题