与Intent.putExtra发送阵列阵列、Intent、putExtra

由网友(云朵上的棉花糖)分享简介:我有一个整数的活性的数组:I have an array of integers in the activity A:int array[] = {1,2,3};和我想的变量发送到活动B,所以我创建了一个新的意图和使用putExtra方式:And i want to send that variable to t...

我有一个整数的活性的数组:

I have an array of integers in the activity A:

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

和我想的变量发送到活动B,所以我创建了一个新的意图和使用putExtra方式:

And i want to send that variable to the activity B, so i create a new intent and use the putExtra method:

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

在b活动我得到的信息:

In the activity B i get the info:

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

但是,这是不是真的发送的ArrayB的数组,我刚刚得到的值0。我一直在寻找一些例子,但我没有发现任何东西左右。

But this is not really sending the array, i just get the value '0' on the arrayB. I've been looking for some examples but i didnt found anything so.

推荐答案

正在设置额外的一个数组。然后,您试图得到一个int类型。

You are setting the extra with an array. You are then trying to get a single int.

您code应该是:

int[] arrayB = extras.getIntArray("numbers");
阅读全文

相关推荐

最新文章