发送活动中的代码。
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putParcelableArrayListExtra("bitmaps", bitmapArrayList);
startActivity(intent);
在接收活动中的代码:
Intent intent = getIntent();
bitmapArrayList = intent.getParcelableArrayListExtra("bitmaps");
一进入接收活动,应用程序就崩溃了。请帮助我们。
你不应该把这种数据从Activity A发送到B,应该在它们之间使用某种媒介类,在那里你可以设置这些数据,然后检索,比如repository。Bundles和Intents不是为大数据设计的。也可以考虑保留Ids或URI-s,并从另一个活动中访问它们,而不是直接发送纯位图。
文档。https:/developer.android.comreferenceandroidosTransactionTooLargeException。
Binder事务缓冲区有一个有限的固定大小,目前是1Mb,它被进程中的所有事务共享。因此,当有许多事务正在进行时,即使大多数单个事务的大小适中,也会抛出这个异常。
Bitmap扩展了Parcelable,这意味着你可以提供一个这样的列表。
ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();
// Poupulate list here
Intent intent = new Intent();
intent.putParcelableArrayListExtra("list", bitmapList);
然后你可以在你的接收活动中把它转换为一个Bitmap[]:
Bitmap[] bitmapArray = bitmapList.toArray(new Bitmap[bitmapList.size()]);
但请记住,一般来说,在你的意图中放太多东西是不好的做法。最好是将你的数据存储起来(DB、文件系统、单体......),然后传递URI或ID。