1

I have build an android application which has a main menu. In the main menu the user can select different "apps" that opens a new Activity with a Runnable.

The menu gets displayed over a custom ListViewAdapter. Every element in the adapter holds a bitmap of displayed menu entry. My Bitmaps uses ~3 MB memory.

So my question is if its wise to free the menu entries when the user opens an under app and build it new when he return to the menu.

EDIT: So I think I did not describe my problem or the question good enough. The main menu has a List of the custom object MenuEntry. Every MenuEntry holds an Drawable for the displayed icon. My ListView has an Adapter that takes the Drawable and use it in an ImageView for displaying the icon in the MenuEntry.

So I think that it would be a good idea to drop my list of MenuEntry when the MainMenu Activity gets paused to free up some memory (~3 MB). And build the Entries new when the user reopens the main menu.

Nightmare
  • 53
  • 5

2 Answers2

0

I propose to compress bitmaps to byte array and save it to collection or array. In your ListViewAdapter set bitmap from byte array. Examples of bitmap compression you can find here: Android : Bitmap save to location

Community
  • 1
  • 1
Taras Shevchuk
  • 331
  • 2
  • 12
  • And the advantage of a `byte[]` against a `Bitmap` is? I mean you lose some vital information like bitmap dimensions and the removal of the header and additional information should be ignorable compared to the memory the pure pixel information consume. – WarrenFaith Sep 07 '12 at 10:40
  • In case if your images are larger then required then you can decrease image width and height here. Also I suppose that byte[] with png image will take less memory than the same Bitmap but I'm not sure. Also such use case uses Java memory but not memory pool for Bitmaps in JNI. – Taras Shevchuk Sep 07 '12 at 11:10
  • PNG is just a compression. If you load a PNG or a Bitmap in the memory, the memory consumption should be the same. You can scale using a `Bitmap`, too. – WarrenFaith Sep 07 '12 at 11:31
0

I do not quite understand why "element in the adapter holds a bitmap". Maybe this will be helpful: LazyList - stores bitmaps in the disk cache: Lazy load of images in ListView

Displaying Bitmaps Efficiently - http://developer.android.com/training/displaying-bitmaps/index.html

Community
  • 1
  • 1
anber
  • 3,463
  • 6
  • 39
  • 68