租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

android parcel传递数组的有哪些方法,安卓传送数据在哪里输入代码

发布时间:2024-03-18 18:05:33

android parcel传递数组的有哪些方法

在Android中,可使用Bundle类来传递数组。首先,将数组放入Bundle中,然后将Bundle传递给Intent对象,最后在接收方从Intent对象中获得Bundle并取出数组。

示例代码以下:

发送方:

String[] array = {"item1", "item2", "item3"};
Bundle bundle = new Bundle();
bundle.putStringArray("myArray", array);

Intent intent = new Intent(this, ReceiverActivity.class);
intent.putExtras(bundle);
startActivity(intent);

接收方:

Bundle bundle = getIntent().getExtras();
String[] array = bundle.getStringArray("myArray");
// 现在你可使用获得的数组array进行操作