5

I am doing an App which access the gprs .I am facing problem when the user starts another application who uses gprs also like google maps .It takes it own heap memory ,after doing some operation on Maps app it calls OnLowMemory of my service .and my ui is also killed in background. I am not getting any proper tutorial haw can i start my app when it is getting killed during onLowMemory ,or is there any other way to handle it .

Thanks in advance.

Sam97305421562
  • 3,027
  • 10
  • 35
  • 45

1 Answers1

6

There's no way you can relaunch your app. The Android OS takes care of killing low priority apps when it starts running out of memory. What you should do is try to save any state before your app gets killed. When the app is launched again, check if there's any state saved and restore your app to the last state.

You should also look as to why your phone is running low on memory, maybe your app is not cleaning up properly or using too many images, bitmaps, etc that use up a lot of memory?

Ricardo Villamil
  • 5,031
  • 2
  • 30
  • 26
  • I have stored the state of Intents in HashMap rather saving in bundle .Have you any tutorial related to state saving because I have made my main class as single instance – Sam97305421562 May 06 '10 at 06:11
  • Well, saving in bundle allows Android to do a lot for of the dirty work for you, like autopassing it to onCreate when your app is relaunched. Check this out: http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state – Ricardo Villamil May 17 '10 at 18:39
  • Saving in a bundle only works up to a point - you'll definitely get out of memory conditions if trying to do this with large groups of data. A better answer if your data is that large is to save everything in a serializeable object as a file in your onPause, and load it back in using onResume. Besides, onPause will get called, but onDestroy may not. It also allows your activity to restore itself to where it needs to be regardless of how it was killed. – Tony Maro Jan 07 '12 at 20:56
  • If your mobile app really depends on having that much data in memory to work, you should rethink its design, only keep (cache) in memory as little data as possible, and write to disk (file or sqlite) the bulk of your data. – Ricardo Villamil Feb 02 '12 at 16:29