title: Handle Notification hide, when app crashes/killed
body: <p>I'm creating a music player application.</p>
  
  <p>When the music plays I'm displaying a <code>notification</code> of current song (similar to default Android music player app).</p>
  
  <p>I'm running music in a <code>Service</code> and handling notification show/hide within that service only.</p>
  
  <p>When the application gets destroyed abruptly/crashes, the music service is stopped &amp; so is the music in the background (which is a correct behavior, i guess).</p>
  
  <p>But even after crash, the notification still remains.</p>
  
  <p>How can I handle this issue?</p>
  
  <p><strong><em>One scenario handled:</em></strong></p>
  
  <p>Music Service is running and notification is displayed.</p>
  
  <p>User clicks on <code>recent apps</code> and kills my application, so service stops , but notification still visible.</p>
  
  <p><strong><em>How I handled it:</em></strong></p>
  
  <p>It is expected that if music is playing and user finishes the <code>MainActivity</code>, then music should keep playing in the background.</p>
  
  <p>So , if <code>backpressed == true</code>, then in <code>onDestroy()</code>, do not cancel the notification. (Activity finished by user)</p>
  
  <p>Else, if <code>backpressed == false</code>, then in <code>onDestroy()</code>, the notification. (Activity killed abruptly)</p>
  
  <pre><code>@Override
  public void onBackPressed() {
      super.onBackPressed();
      mBackPressed = true;
  }
  
  @Override
  protected void onDestroy() {
      if (!mBackPressed) {
          mMusicService.hideStatusBarNotification();
      }
  
      super.onDestroy();
      Log.e(TAG, "onDestroy() called - Activity");
  }
  </code></pre>
  
  <p>Is this handling a good approach.</p>
  
  <p><strong>Also, this is just one scenario, I cant think of how application+service can be killed abruptly, &amp; how to handle it?</strong></p>
  
  <p>Thank You</p>