Android 如何将捆绑阵列发送到其他活动?

Android 如何将捆绑阵列发送到其他活动?,android,android-intent,bundle,Android,Android Intent,Bundle,我有一个Bundle数组,我将把它发送到另一个活动 发射机: List<Bundle> items = new ArrayList<>(); // add items Intent intent = new Intent(this, Dialog.class); intent.putExtra("items", items.toArray()); startActivity(intent); Bundle[] items = (Bundle[]) getIntent(

我有一个
Bundle
数组,我将把它发送到另一个活动

发射机:

List<Bundle> items = new ArrayList<>();
// add items

Intent intent = new Intent(this, Dialog.class);
intent.putExtra("items", items.toArray());
startActivity(intent);
Bundle[] items = (Bundle[]) getIntent().getExtras().getSerializable("items");
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myApp/com.example.myApp.items.ReceverActivity}: java.lang.ClassCastException: java.lang.Object[] cannot be cast to android.os.Bundle[]
但其返回错误:

List<Bundle> items = new ArrayList<>();
// add items

Intent intent = new Intent(this, Dialog.class);
intent.putExtra("items", items.toArray());
startActivity(intent);
Bundle[] items = (Bundle[]) getIntent().getExtras().getSerializable("items");
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myApp/com.example.myApp.items.ReceverActivity}: java.lang.ClassCastException: java.lang.Object[] cannot be cast to android.os.Bundle[]

捆绑包不可
序列化
,但它确实实现了
可打包
。您可以使用传递
ArrayList
,并检索它。还有一对用于传递和检索数组,您必须使用array

Bundle不
Serializable
,但它确实实现了
Parcelable
。您可以使用传递
ArrayList
,并检索它。还有一对用于传递和检索数组,您必须使用array

Bundle array
这是什么?Bundle[]或Bundle.toArray()但是一个捆绑包中的项目还不够吗?你需要一个捆绑包数组吗?没有项目不是一个捆绑包。它是一个列表,将转换为一个arraygetExtras只返回一个捆绑包,因此在你的代码
捆绑包数组中某个东西失败了
这是什么?捆绑包[]或捆绑包。toArray()一个bundle中的项目是否足够?您需要一个bundle数组吗?没有项目不是一个bundle它是一个列表,将被转换为arraygetExtras只返回一个bundle,因此代码中的某个项目失败