android - 将二维对象数组传递给另一个 Activity

标签 android

不幸的是(据我所知)我正在尝试传递(对象)数组,可序列化 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");

also it is a similar problem here

关于android - 将二维对象数组传递给另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038633/

相关文章:

java - 尝试建立本地连接时出错

android - 停止在 ListView 中滚动

android - 造型 Sherlock 操作栏下拉项目

java - 如何在 Eclipse Java 构建路径中添加 android-async-http.JAR

c# - 根据日期对列表进行分组,每个项目有多个日期

android - 如何升级Android Studio 2.3构建工具25修复 "The SDK Build Tools revision (21.1.2) is too low for project Minimum required is 25.0.0"

android - 使用适配器为 Gallery 小部件正确缩放图像

android - Log.e 不打印 UnknownHostException 的堆栈跟踪

android - loginButton.registerCallback 无法解析方法

android - 如何以最短加载时间(2 秒)在 AsyncTask 中添加进度对话框