2

I have a ViewFlipper in which, in each of its subviews, I put a bitmap on it. The thing is that I am worried that my application (in special, that Activity) will run out of memory and throw an (OutOfMemory) exception.

I thought in capturing the "OutOfMemory" exception, but that would be too late already...

I want to implement some callback method for when my activity is "about to run out of memory" (like, it will run out of memory if I allocate 2 or 3 more bitmaps).

Is there any method we can implement so I can free some of those loaded bitmaps inside it? I don't want to free the bitmaps if my application still has plenty of memory to have the bitmaps in memory.

Thanks in advance!

slayton
  • 20,123
  • 10
  • 60
  • 89

1 Answers1

3

You can verify free memory of the system at that point

How do I discover memory usage of my application in Android?

In android 4.1 New ComponentCallbacks2 constants such as TRIM_MEMORY_RUNNING_LOW and TRIM_MEMORY_RUNNING_CRITICAL provide foreground processes more information about memory state before the system calls onLowMemory().

Community
  • 1
  • 1
Vishwanath.M
  • 6,235
  • 11
  • 42
  • 56