title: What is the proper way to stop a service running as foreground
body: <p>I am trying to stop a service which is running as foreground service.</p>
  
  <p>The current issue is that when I call <code>stopService()</code> the notification still stays.</p>
  
  <p>So in my solution I have added a receiver which I am registering to inside the <code>onCreate()</code></p>
  
  <p>Inside the <code>onReceive()</code> method I call <code>stopforeground(true)</code> and it hides the notification.
  And then <code>stopself()</code> to stop the service.</p>
  
  <p>Inside the <code>onDestroy()</code> I unregistered the receiver.</p>
  
  <p>Is there a more proper way to handle this? because stopService() simply doesn't work.</p>
  
  <pre><code>@Override
  public void onDestroy(){
    unregisterReceiver(receiver);
    super.onDestroy();
  }
  </code></pre>