【问题标题】:Passing 2D array of objects to another Activity将二维对象数组传递给另一个活动
【发布时间】:2015-07-14 08:10:36
【问题描述】:

不幸的是(据我所知)可序列化捆绑包不适用于自定义对象。

我有班级座位:

   public class seat{
    boolean state;
    int Seatb;
    }

这是第一个活动的代码:

seat [][] arrseat=new seat[20][20];
Intent intent = new Intent(this, MainActivity2.class);
intent.putExtra("data", arrseat);
startActivity(intent);

第二个活动:

seat [][] obseat=new seat[20][20];
Intent intent = getIntent();
obseat=intent.?

我找不到从意图中获取数组的方法

【问题讨论】:

标签: android


【解决方案1】:

数组是可序列化的,所以你可以使用 putSerializable。 放价值

Intent i = new Intent(this, AnotherClass.class);
Bundle b = new Bundle();
b.putSerializable("arr", seat);
i.putExtras(b);

获得价值

seat[][] arrseat = (seat[][]) bundle.getSerializable("arr");

also it is a similar problem here

【讨论】:

  • b.putSerializable("arr", 座位);不适用于对象数组
  • @kalebora之所以不起作用是因为seat需要实现Serializable接口
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多