简体   繁体   中英

Android - how to pass a List of Bitmap to another Activity as parameter

I have a List of Bitmap in an Activity, that i got through async method. Now i need to pass my List of Bitmap to another activity.

Here is the code i tried, but gives me an error...

 List<Bitmap> result = bitmapResult
 Intent intent = new Intent(PhotoList.this,ImageSlider.class);
 intent.putExtra("bitmapList", result);
 startActivity(intent);

It gives me an error.

Cannot resolve method 'putExtra(java.lang.String, java.util.List<android.graphics.Bitmap>)'

What is the best practice to do it? And how can i retrive the List from the new Activity?

Thanks in advance.

Since we are not aware how big is your Bitmap array and could potentially hit the allotted limited of passing over intent. The ideal approach is to store your bitmap as image in your SDCard/Phone storage and gets its Uri. Therefore you only need to send the array of Uri Strings eg List<String> rather than List<Bitmaps>

In activity which you need, you have to receive List you send before.

List<Bitmap> result = bitmapResult
Intent intent = new Intent(PhotoList.this,ImageSlider.class);
intent.putExtra("bitmapList", result);
startActivity(intent);

Receive activity;

List<Bitmap> receive = (List<Bitmap> getIntent.getExtra.get("bitmapList");

After that, you using "for loop" to set any item which you need. You can use ArrayList, it simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM