Keep My App alive - Android
<p>I'm trying to make an App on Android 2.2 that has to run whether the screen is on or off.</p>

<p>I tried realizing it via a Service, but when my phone turns the screen off the service stopps working and I don't understand why.</p>

<p>In my Application I use</p>

<pre><code>startService(new Intent(this, MyService.class));
</code></pre>

<p>when the User presses a button</p>

<p>and </p>

<pre><code>Notification notification = new Notification();
startForeground(1, notification);
</code></pre>

<p>in the onCreate-Method of the Service class </p>

<p>(I tried it within the onStart() Method, too)</p>

<p>(I also could not find out what the id-field of startForeground() expects so I used the 1)</p>

<p>The service then should start an infinite vibration pattern of the phone so I know whether it is running or not.
But when I turn off the screen, the phone stops vibration immediately </p>

<p>Please help me. I don't know how I can fix that (and google was not a big help)</p>

<p>Sincerely
zed</p>
