title: Service onDestroy called without onStartCommand
body: <p>I'm getting reports of a <code>NullPointerException</code> when the <code>onDestroy()</code> service method gets called. The part that i don't understand is that i always start the service with a <code>Context.startService()</code> so the <code>onStartCommand()</code> should always be called and the reference should never be null.</p>
  
  <p>It is worth mentioning, that the <code>NullPointerException</code> doesn't happen when i shutdown the service with <code>Context.stopService()</code> call. </p>
  
  <p>So my conclusion is that the framework is calling <code>onDestroy()</code> without having called <code>onStartCommand()</code>. I'm guessing that the Service might be being destroyed, and restarted by the framework so <code>onStartCommand()</code> doesn't actually gets executed. But again, this is me just guessing.</p>
  
  <p>Any ideas on what might be going on here? Thanks!</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>public class ServiceLocationListener extends Service 
  
      private NotificationManager mNotificationManager;
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          super.onStartCommand(intent, flags, startId);
          mNotificationManager = getService(this, Context.NOTIFICATION_SERVICE);
          mNotificationManager.notify(SOME_NOTIFICATION_ID, someNotification);
          ...
          return START_STICKY;
      }
  
      @Override
      public void onDestroy() {
          mNotificationManager.cancel(SOME_NOTIFICATION_ID);  &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; NPE
          ...
      }
  }
  </code></pre>