如何通过一个ArrayList的<位图>活动之间 [英] How to pass a ArrayList<Bitmap> between activities

查看:101
本文介绍了如何通过一个ArrayList的<位图>活动之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ArrayList<位图> 我使用该方法已填充 getBitmapFromAsset(),并想通过它通过使用捆绑的意图。然而,它可以让我通过其他的ArrayList像的ArrayList<字符串> 使用:

I have an ArrayList<Bitmap> that I have populated using the method getBitmapFromAsset() and want to pass it via intent using a Bundle. However it allows me to pass other ArrayLists like ArrayList<String> using:

Intent intent = new Intent(myClass.this, Rclass.class);  
Bundle bundle = new Bundle();    
bundle.putStringArrayList("names", (ArrayList<String>) names);  
intent.putExtras(bundle);
startActivity(intent);

但我不知道如何通过类型位图的ArrayList,因为我看不到的捆绑选项。如何进行任何想法?

But I don't know how to pass an ArrayList of the type Bitmap as I don't see that option in the Bundle. Any ideas of how to perform this?

推荐答案

薪火位图本身从一个活动到另一个是非常低效的内存。这可能是确定的,如果你的位图是小尺寸的图标,但如果是大的位图,您可能会遇到内存不足的异常。

Passing the bitmaps itself from one activity to another is very memory inefficient. It may be OK if your bitmaps are small size icons, but if they are large bitmaps, you may encounter out of memory exception.

你有没有考虑这个重构一点点,如使用一个单独的有位图ID(或资产名称)一个HashMap位图本身的WeakReference。这个单,我们称之为BitmapHelper,会自动从资产重新加载位图,如果它尚未加载或已释放被垃圾收集器。

Have you consider refactor this a little bit, e.g. Use a singleton that has a HashMap of Bitmap ID (or asset name) to WeakReference of the bitmap itself. This singleton, let's call it BitmapHelper, will auto reload the bitmap from the asset, if it has not yet been loaded or has been freed by the garbage collector.

在你有这个BitmapHelper,那么它是通过位图ID /资产名称的字符串数组到另一个活动的问题。从其他活动,你可能刚刚从BitmapHelper访问的位图。

After your have this BitmapHelper, then it's a matter of passing the bitmap id/asset name in a String Array to another activity. From the other activity, you could just access the bitmap from the BitmapHelper.

这篇关于如何通过一个ArrayList的&LT;位图&GT;活动之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆