Passing 2D array of objects to another Activity

时间:2015-05-04 19:42:29

标签: android

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 个答案:

答案 0 :(得分:2)

Arrays are serializable, So you can use putSerializable. to put value

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