6

In iOS an app will receive a memory warning by implementing a function called DidReceiveMemoryWarning, which means the RAM is not enough to use. If a Level 2 version of this warning is sent, the app will probably be force stopped.

Is there something similar (like a broadcast intent) in Android to tell my app that we're out of RAM and i could remove some objects programmatically?

Thanks.

1 Answers1

9

You should define your own custom application object by extending Android Application class and define that object in the Application tag in the manifest file. In this custom object you can override the onLowMemory() method.

Hope this helps you.

Gopinath
  • 12,981
  • 6
  • 36
  • 50
  • 4
    Note that this doesn't prevent OutOfMemoryErrors. `onLowMemory()` raises when the **system global memory is low**. If the global memory is okay but your process takes more than 24MB on old Android devices, it will crash and you'll never get a low memory warning. I know, it's a shame. – cprcrack Aug 07 '14 at 11:58
  • @cprcrack Thanks a lot for your hint. This is important! – Garfield the Dummy Aug 22 '14 at 10:02