title: The onStop() of activity is not called when activity no longer visible
body: <p>In a normal situation, as per <a href="https://developer.android.com/guide/components/activities/activity-lifecycle#onstop" rel="nofollow noreferrer">https://developer.android.com/guide/components/activities/activity-lifecycle#onstop</a>, it is indicated</p>
  <p><code>When your activity is no longer visible to the user, it has entered the Stopped state, and the system invokes the onStop() callback. This may occur, for example, when a newly launched activity covers the entire screen.</code></p>
  <p>I have an example design below
  <a href="https://github.com/elye/issue_android_activity_not_stop_when_not_visible" rel="nofollow noreferrer">https://github.com/elye/issue_android_activity_not_stop_when_not_visible</a></p>
  <pre><code>class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
      }
  
      override fun onStart() {
          super.onStart()
          Log.d(&quot;Track&quot;, &quot;MainActivity: onStart&quot;)
      }
  
      override fun onStop() {
          super.onStop()
          Log.d(&quot;Track&quot;, &quot;MainActivity: onStop&quot;)
      }
  
      override fun onResume() {
          super.onResume()
          Log.d(&quot;Track&quot;, &quot;MainActivity: onResume&quot;)
      }
  
      override fun onPause() {
          super.onPause()
          Log.d(&quot;Track&quot;, &quot;MainActivity: onPause&quot;)
      }
  
      fun onButtonClicked(view: View) {
          startActivity(Intent(this, NextActivity::class.java))
      }
  
      override fun onNewIntent(intent: Intent?) {
          super.onNewIntent(intent)
          startActivity(Intent(this, NextActivity::class.java))
      }
  }
  </code></pre>
  <p>In this design, the <code>MainActivity</code> will launch <code>NextActivity</code>. In normal launch using the Button to click, the <code>MainActivity</code> does call <code>onStop</code> as it launches the <code>NextActivity</code></p>
  <p>To replicate the case where <code>onStop()</code> of <code>MainActivity</code> is not called when <code>MainActivity</code> is not visible anymore, below is the step</p>
  <ol>
  <li>Open up <code>MainActivity</code> (which is <code>singleTask</code>)</li>
  <li>Deeplink through <code>DeeplinkActivity</code> (which is <code>singleInstance</code>) using</li>
  </ol>
  <pre><code>adb shell am start -a android.intent.action.VIEW -d &quot;https://www.onstoptrigger.com/test&quot;
  </code></pre>
  <p>The <code>DeeplinkActivity</code> will trigger the <code>onNewIntent()</code> of <code>MainActivity</code>. In the <code>onNewIntent()</code>, it will launch <code>NextActivity</code>.</p>
  <p>Here, when <code>NextActivity</code> is launched, the <code>MainActivity</code> only called <code>onPause()</code>. The <code>MainActivity</code>'s <code>onStop()</code> is not called. Is this expected?</p>
  <p>I feel like it's an Android bug but would love to be corrected.</p>
  <p>Note:</p>
  <ol>
  <li>If I change <code>DeeplinkActivity</code> to <code>singleTask</code>, the problem doesn't occur</li>
  <li>If I deeplink directly into <code>MainActivity</code> (without using <code>DeeplinkActivity</code>, the problem doesn't occur too</li>
  </ol>