发送带有 Intent.putExtra 的数组

12 浏览
0 Comments

发送带有 Intent.putExtra 的数组

我在Activity A中有一个整数数组:

int array[] = {1,2,3};

我想将该变量发送到Activity B,所以我创建了一个新的Intent并使用putExtra方法:

Intent i = new Intent(A.this, B.class);
i.putExtra("numbers", array);
startActivity(i);

在Activity B中,我获取到了这个信息:

Bundle extras = getIntent().getExtras();
int arrayB = extras.getInt("numbers");

但实际上这并没有真正发送数组,我只是在arrayB中得到了值'0'。我一直在寻找一些例子,但是没有找到什么。

0