I have been looking for a solution and I found many different opinions to solve my problem.
Here is what my app is doing:
-
It does a search in a database and it assembles
nscreens withnpictures. Each picture is anImageButtonand each one has its own image, action, etc. depending on what is stored in the database. -
The created screens are thrown inside of a
ViewFlipper. -
Some items have “children”.
- So, if a user clicks on an ImageButton with a “child”, it will search the database, get items, assemble the new screen(s) with ImageButtons with informations from database.
- Then, Add this (these) new screen(s) to the
ViewFlipperand keep a reference from the caller screen, so user may return to the caller screen if he wishes.
-
It will do the item 3 whenever an
ImageButtonhas “children” according to the database. -
It’s easy to see that there will be lots of screens in the initial
ViewFlipper. -
It works flawlessly in my Asus EEE Pad Transformer. However if I try to run it in my Galaxy S (less memory) it will eventually crash (lack of memory exception) if I keep on browsing screens.
What’s the best way for me to free up memory in this situation?
It is probably not going to be easy, but if you want to save memory – save on the views. Instead of building all the views in advance, build only the ones you need, and manage the flipping manually. After all, you only need to show one image at a time, so prepare that, and perhaps the one before that and the one after that for quick flipping, but don’t prepare everything else before needed.