溫馨提示×

android parcel傳遞數組的方法是什么

小億
115
2024-03-18 18:05:33
欄目: 編程語言

在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進行操作

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女