title: Cancel notification on remove application from multitask panel
body: <p>I manage an <strong>ONGOING</strong> notification from my application (not from a service).</p>
  
  <p>When I kill application from task manager with "End" button, <strong>notification disappear</strong>.</p>
  
  <p>When I remove application from multitask pannel, application is killed but <strong>notification remains</strong>.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>How to catch this event to clear notification?</li>
  <li>What happens when application is removed from multitask pannel? Application is destroyed but process staying alive? Is it normal?</li>
  </ul>
  
  <hr>
  
  <p>As an update:</p>
  
  <p>All my activities extends MyActivity class (which extends Activity) with methods:</p>
  
  <pre><code>@Override protected void onCreate(Bundle state) {
      super.onCreate(state);
      ((MyApplication) getApplication()).onActivityCreate(this, state);
  }
  
  @Override protected void onDestroy() {
      super.onDestroy();
      ((MyApplication) getApplication()).onActivityDestroy(this);
  }
  </code></pre>
  
  <p>And my application extends MyApplication class (which extends Application) with methods:</p>
  
  <pre><code>private List&lt;Activity&gt; activities = new ArrayList&lt;Activity&gt;();
  
  protected final void onActivityCreate(Activity activity, Bundle state) {
      if(activities.isEmpty() &amp;&amp; state == null) {
          onStart();
      }
      activities.add(activity);
  }
  
  protected final void onActivityDestroy(Activity activity) {
      activities.remove(activity);
      if(activities.isEmpty() &amp;&amp; activity.isFinishing()) {
          onExit();
      }
  }
  
  protected void onStart() {
      // some code
  }
  
  protected void onExit() {
      // some code
      notificationManager.cancel(NOTIFICATION_ID);
  }
  </code></pre>
  
  <p><code>activities</code> is a list of all running activities</p>
  
  <p>It's not simplest mechanism but I need it</p>
  
  <p>Should I use a service instead?</p>
  
  <hr>
  
  <p>As a new update:</p>
  
  <p>In my onExit() method, if I Log debug message to know what happens like this:</p>
  
  <pre><code>public void onExit() {
      for(int i = 0; i &lt; 100; i++) {
          Log.d(TAG, "onExit");
      }
  }
  </code></pre>
  
  <p>a small amount of log appears once on two, not all (ex: 13/100)</p>
  
  <p>So, I understand that remove application from multitask pannel force to kill application without waiting close methods end to finish properly... But why not process ?!</p>
  
  <p>How can I force to terminate properly ?</p>