title: android: how to cleanup application when it is killed
body: <p>I'm working on an android application, my application turns on some HW on the phone.
  I want to close the HW in case anyone kills my application.
  how can i "catch" the kill command/event/signal and do a cleanup before application exit?</p>
  
  <hr>
  
  <p>Some update what I found.
  You can't protect your application from being killed in all cases.
  onDestroy() is not guaranteed to be called (in case of OOM killer for example, or user calling killall -9 xxx).
  Best you can do is implement the onDestroy() function, add handler for sig_term and register your application as out of scope for the OOM killer.</p>
  
  <p>This should handle 90% of the cases.
  All other cases are from specific user activity - so he will get what we wanted i guess...</p>