如何将捆绑数组发送到另一个 activity?
How can I send a bundle array to another activity?
我有一个 Bundle
数组,我要将它发送给另一个 activity
传送器:
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");
但是它的return错误:
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[]
Bundle 没有 Serializable
,但它确实实现了 Parcelable
。您可以使用 putParcelableArrayList to pass your ArrayList<Bundle>
, and getParcelableArrayList 来检索它。还有一对传递和检索数组,你必须使用 array
我有一个 Bundle
数组,我要将它发送给另一个 activity
传送器:
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");
但是它的return错误:
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[]
Bundle 没有 Serializable
,但它确实实现了 Parcelable
。您可以使用 putParcelableArrayList to pass your ArrayList<Bundle>
, and getParcelableArrayList 来检索它。还有一对传递和检索数组,你必须使用 array