title: Foreground service issue - did not then call Service.startForeground()
body: <p>Found an interesting observation with foreground service, if we stop the service immediately right just after start foreground service we get this error as <strong>Context.startForegroundService() did not then call Service.startForeground()</strong>. Doesn't matter whether we start notification from onCreate or onStartCommand of service.</p>
  <pre><code>Intent intent = new Intent(this, MyService.class)
  startForegroundService(intent);
  stopService(intent);
  </code></pre>
  <p>But if I add a delay then it's working as expected, any thought on this ?</p>
  <pre><code>Intent intent = new Intent(this, MyService.class)
  startForegroundService(intent);
  new Handler(Looper.getMainLooper()).postDelayed(() -&gt; stopService(intent), 0);
  </code></pre>
  <p><strong>In order to get rid of this error this is how I fixed</strong></p>
  <blockquote>
  <p>I didn't found any proper documentation on developer website but this is what
  I did in order to solve <strong>Context.startForegroundService() did not
  then call Service.startForeground()</strong> issue.</p>
  <p>If we want to stop foreground service do not call outside the service
  class using <strong>stopService(intent)</strong> instead create an intent action,
  start the foreground service then stop the service using stopSelf from
  service onStartCommand.</p>
  <pre><code>Intent serviceIntent = new Intent(context, MyService.class);
  serviceIntent.setAction(ACTION_STOP_SERVICE);
  ContextCompat.startForegroundService(context, serviceIntent);
  </code></pre>
  </blockquote>