title: Android: keeping a background service alive (preventing process death)
body: <p>I have a service that is defined as:</p>
  
  <pre><code>public class SleepAccelerometerService extends Service implements SensorEventListener
  </code></pre>
  
  <p>Essentially, I am making an app that monitors accelerometer activity for various reasons while the user sleeps with his or her phone/device on the bed. This is a long-running service that MUST NOT be killed during the night. Depending on how many background apps and periodic processes occur during the night, android sometimes kills off my process, thereby ending my service. Example:</p>
  
  <pre><code>10-04 03:27:41.673: INFO/ActivityManager(1269): Process com.androsz.electricsleep (pid 16223) has died.
  10-04 03:27:41.681: INFO/WindowManager(1269): WIN DEATH: Window{45509f98 com.androsz.electricsleep/com.androsz.electricsleep.ui.SleepActivity paused=false}
  </code></pre>
  
  <p>I do not want to force the user to have 'SleepActivity' or some other activity in my app as the foreground. I can't have my service run periodically, because it is constantly intercepting onSensorChanged.</p>
  
  <p>Any tips? source code is here: <a href="http://code.google.com/p/electricsleep/" rel="noreferrer">http://code.google.com/p/electricsleep/</a></p>