Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我应该如何将位图的ArrayList从一个活动发送到另一个活动?我_Android_Arraylist_Android Intent_Bitmap_Parcelable - Fatal编程技术网

Android 我应该如何将位图的ArrayList从一个活动发送到另一个活动?我

Android 我应该如何将位图的ArrayList从一个活动发送到另一个活动?我,android,arraylist,android-intent,bitmap,parcelable,Android,Arraylist,Android Intent,Bitmap,Parcelable,发送活动中的代码: Intent intent = new Intent(MainActivity.this,Main2Activity.class); intent.putParcelableArrayListExtra("bitmaps", bitmapArrayList); startActivity(intent); Intent intent = getIntent(); bitmapArrayList = intent.getParcel

发送活动中的代码:

    Intent intent = new Intent(MainActivity.this,Main2Activity.class);
    intent.putParcelableArrayListExtra("bitmaps",  bitmapArrayList);
    startActivity(intent);
    Intent intent = getIntent();
    bitmapArrayList =  intent.getParcelableArrayListExtra("bitmaps");
Bitmap[] bitmapArray = bitmapList.toArray(new Bitmap[bitmapList.size()]);
接收活动中的代码:

    Intent intent = new Intent(MainActivity.this,Main2Activity.class);
    intent.putParcelableArrayListExtra("bitmaps",  bitmapArrayList);
    startActivity(intent);
    Intent intent = getIntent();
    bitmapArrayList =  intent.getParcelableArrayListExtra("bitmaps");
Bitmap[] bitmapArray = bitmapList.toArray(new Bitmap[bitmapList.size()]);

进入接收活动后,应用程序立即崩溃。请提供帮助。

位图扩展了Parcelable,这意味着您可以提供如下列表:

 ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();
// Poupulate list here

Intent intent = new Intent();
intent.putParcelableArrayListExtra("list", bitmapList);

但请记住,在你的意图中放太多东西通常是不好的做法。最好存储数据(数据库、文件系统、单例等)并传递URI或ID。

位图扩展了Parcelable,这意味着您可以提供如下列表:

 ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();
// Poupulate list here

Intent intent = new Intent();
intent.putParcelableArrayListExtra("list", bitmapList);

但请记住,在你的意图中放太多东西通常是不好的做法。最好将数据存储(DB、文件系统、单例等)并传递URI或ID。

您不应该将此类数据从活动A发送到活动B。在它们之间使用某种中间类,您可以设置这些数据,然后检索,如存储库。捆绑包和意图不是为大数据而设计的。还考虑保持IDS或URIs,并从另一个活动中访问它们,而不是直接发送普通位图

。 文件:

活页夹事务缓冲区有一个有限的固定大小,当前为1Mb,该大小由流程中所有正在进行的事务共享。因此,当有许多事务正在进行时,甚至当大多数单个事务的大小适中时,也会引发此异常


您不应该将此类数据从活动A发送到B。在它们之间使用某种中间类,您可以在其中设置这些数据,然后进行检索,如存储库。捆绑包和意图不是为大数据而设计的。还考虑保持IDS或URIs,并从另一个活动中访问它们,而不是直接发送普通位图

。 文件:

活页夹事务缓冲区有一个有限的固定大小,当前为1Mb,该大小由流程中所有正在进行的事务共享。因此,当有许多事务正在进行时,甚至当大多数单个事务的大小适中时,也会引发此异常


即使将应用程序存储在位图数组中,应用程序仍然崩溃。不,但应用程序崩溃了。即使将应用程序存储在位图数组中,应用程序仍然崩溃。不,但应用程序崩溃了。好的,我会调查的。你能给我提供一些通过URI-s学习的链接吗?我想没有具体的链接/教程来学习如何通过URI做到这一点。如果要从文件创建位图,URI将是文件的地址。我在回答中的意思是,只保留一个引用,不要发送原始位图,传递文件的id或URI,然后在另一个活动中检索它。好的,我会调查的。你能给我提供一些通过URI-s学习的链接吗?我想没有具体的链接/教程来学习如何通过URI做到这一点。如果要从文件创建位图,URI将是文件的地址。我在回答中的意思是,只保留一个引用,不发送原始位图,传递文件的id或URI,然后在另一个活动中检索它。