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