title: Service code stops when application is stopped
body: <p>I have an app that gets users messages from database and if there is a new message it pushes a notification i use a service for that.. The service works fine when the app is opened or in the foreground.. But when I close it it doesn't work.. It is not destroyed or stopped it's just doesn't work :S I don't know why.. This is my service code : </p>
  
  <pre><code>public class BGService extends Service {
  
  ArrayList&lt;Message&gt; messages = new ArrayList&lt;Message&gt;();
  ArrayList&lt;String&gt; requests = new ArrayList&lt;String&gt;();
  Timer timer = new Timer();
  Timer timer2 = new Timer();
  
  @Override
  public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public void onDestroy() {
      Log.d("Chat", "BGService Destroyed");
      timer.cancel();
      timer.purge();
      timer2.cancel();
      timer2.purge();
  }
  
  @SuppressWarnings("unchecked")
  @Override
  public void onStart(Intent intent, int startId) {
      Log.d("Chat", "BGService Started");
      messages = (ArrayList&lt;Message&gt;) intent.getExtras().get("messages");
      requests = (ArrayList&lt;String&gt;) intent.getExtras().get("requests");
      Log.d("Button Clicked", "Messages: " + messages);
  
      new Timer().scheduleAtFixedRate(new TimerTask() {
          public void run() {
              Log.d("Service", "Running");
          }
      }, 2000, 2000);
   }
  }
  </code></pre>