title: ActivityLifecycleCallbacks are not triggered when activity is killed through "Don't keep activities"
body: <p>In my Android app I have two activities:</p>
  
  <ul>
  <li><code>DemoActivity</code> with a button to start the <code>SearchActivity</code> with an <code>Intent</code></li>
  <li><code>SearchActivity</code></li>
  </ul>
  
  <p>The button is a custom ViewGroup:</p>
  
  <ul>
  <li><code>SearchButton</code></li>
  </ul>
  
  <p>As soon as the <code>SearchButton</code> comes to life it registers for lifecycle events (of the corresponding <code>SearchActivity</code>):</p>
  
  <pre><code>public class SearchButton extends CardView implements 
      Application.ActivityLifecycleCallbacks {
  
      @Override
      protected void onAttachedToWindow() {
          super.onAttachedToWindow();
          Context applicationContext = getContext().getApplicationContext();
          if (applicationContext instanceof Application) {
              ((Application) applicationContext)
                  .registerActivityLifecycleCallbacks(this);
          }
      }
  
  // ...
  </code></pre>
  
  <p>The events are consumed as follows:</p>
  
  <pre><code>// ...
  
      @Override
      public void onActivityStarted(Activity activity) {
          if (activity instanceof SearchActivity) {
              SearchActivity searchActivity = (SearchActivity) activity;
              searchActivity.addSomeListener(someListener);
          }
      }
  
      @Override
      public void onActivityStopped(Activity activity) {
          if (activity instanceof SearchActivity) {
              SearchActivity searchActivity = (SearchActivity) activity;
              searchActivity.removeSomeListener(someListener);
          }
      }
  </code></pre>
  
  <p>Once the <code>SearchActivity</code> has been launched I put the app into background and get it back into foreground. The following call stack can be seen:</p>
  
  <pre><code>1. SearchButton.onActivityStarted // triggered by DemoActivity
  2. DemoActivity.onStart
  3. SearchButton.onActivityStarted // triggered by SearchActivity
  4. SearchActivity.addSomeListener
  5. SearchActivity.onStart
  </code></pre>
  
  <p>As you can see the listener is added. This works fine.</p>
  
  <hr>
  
  <h3>The problem</h3>
  
  <p>As soon as I enable <code>Don't keep activities</code> in the developer options the call stack looks like this when I get the app foreground again:</p>
  
  <pre><code>1. DemoActivity.onCreate
  2. SearchButton.init // Constructor
  3. DemoActivity.onStart
  4. SearchActivity.onStart
  5. SearchButton.onAttachedToWindow
  6. DemoApplication.registerActivityLifecycleCallbacks
  </code></pre>
  
  <p>Here the listener is <strong>not added</strong>. The desired <code>onActivityStarted</code> callback triggered by <code>SearchActivity.onStart</code> is <strong>missing</strong>.</p>