2

I'm working an Android AudioRecord app. If I do not call the release() method on the AudioRecord object at the end of the script, it will not run correctly until I restart the phone.

This becomes a major hassle when working on this project because if the app should ever crash (which happens sometimes while testing and there's an unexpected buffer overflow, etc.) then I have to restart the phone every time.

I have the method to release the buffers inside the finalize() method of my AudioListener class, and I also call them onStop() of the main Activity.

Neither of these seem to work when the app freezes or crashes. Is there a way to attach the release action to an error handler or some general way of ensuring that an app will execute some code to release resources properly even after a crash.

Thanks for any help.

chaimp
  • 16,897
  • 16
  • 53
  • 86
  • This will probably help you - http://stackoverflow.com/questions/2654168/global-uncaught-exception-handler-email-log-to-me – Prashast Dec 24 '10 at 06:41

1 Answers1

3

Create your own Application class (need to be declared in AndroidManifest.xml) and then overwrite methods:

Application.onLowMemory();
Application.onTerminate();

More about it can be read in Android manuals for Application

Barmaley
  • 16,638
  • 18
  • 73
  • 146