如何通过一个ArrayList的<位图>活动之间位图、ArrayList、LT、GT

由网友(农村滴娃,拽i)分享简介:我有一个的ArrayList<位图> 我使用该方法已填充 getBitmapFromAsset(),并想通过它通过使用捆绑的意图。然而,它可以让我通过其他的ArrayList像的ArrayList<字符串> 使用:I have an ArrayList that I have...

我有一个的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.

阅读全文

相关推荐

最新文章