Foreground service that does nothing. Is it a good candidate to be killed by the OS?
<p>Maybe the question is obvious, but I would like to be sure based on what my app does.</p>

<p>I am writing a GPS tracker. I use the location services inside a static class to get my positions. Everything works fine. However I have noticed that from time to time my app gets killed when it has been running for a couple of hours. In order to resolve that I thought in converting it to a foreground service.</p>

<p>Instead of rewriting my code and put all my logic inside the service, I thought in just creating a foreground service that does nothing. I will start this service when the user decides to start tracking. Remember that I use the location services inside a static class.</p>

<p>Will this be safe or the OS will find out that this service is not doing anything at all and it will have more chances to be killed?</p>

<p>Here is my service:</p>

<pre><code>public class SimpleService extends Service 
{
    private static final int ONGOING_NOTIFICATION = 1;

    @Override
    public void onCreate() 
    {
        super.onCreate();

        Notification notification = new Notification(R.drawable.icon, "Tracking started", System.currentTimeMillis());
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(this, "notification title", "notification message", pendingIntent);     
        startForeground(ONGOING_NOTIFICATION, notification);
    }


    @Override
    public void onDestroy() 
    {
          super.onDestroy();          
          stopForeground(true);
    }
}
</code></pre>

<p>Thanks</p>
