与Intent.putExtra发送阵列 [英] Sending arrays with Intent.putExtra

查看:137
本文介绍了与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 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");

这篇关于与Intent.putExtra发送阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆