title: Why starting the Activity by an intent (Intent.ACTION_VIEW) doesn't always start a new activity and call onCreate()?
body: <p>I have two Android applications.</p>
  <p>The first application is the &quot;browser&quot;. It gets an URL and displays it in a WebView. The corresponding activity is declared as:</p>
  <pre><code>    &lt;activity android:name=&quot;.MainActivity&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
              &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;
              &lt;data android:scheme=&quot;http&quot; /&gt;
              &lt;data android:scheme=&quot;https&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      
  </code></pre>
  <p>The second application has a few buttons. Tapping each button opens the first application and sends the URL to it using <code>Intent.ACTION_VIEW</code>:</p>
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW);
  Uri uri = Uri.parse(urlString);
  intent.setData(uri);
  intent.setComponent(new ComponentName(&quot;com.custom.browser&quot;, &quot;com.custom.browser.MainActivity&quot;));
  startActivity(intent);
  </code></pre>
  <p>I expect this code to start a new activity as per <a href="https://developer.android.com/reference/android/app/Activity" rel="nofollow noreferrer">https://developer.android.com/reference/android/app/Activity</a>. So the browser application retrieves the URL in <code>onCreate()</code> by using the code:</p>
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      ...
      Intent intent = getIntent();
      if (intent != null &amp;&amp; Intent.ACTION_VIEW.equals(intent.getAction())) {
          displayUrl(intent.getDataString());
      }
      ...
  }
  </code></pre>
  <p>However I found that sometimes <code>onCreate()</code> is not called. After calling <code>startActivity(intent)</code>, the browser application is just brought to the front, therefore displaying a previous URL.</p>
  <p>I can override this behavior by moving the intent retrieval code in the <code>onResume()</code>.</p>
  <p>However I'd like to understand what am I doing wrong? Shouldn't the method <code>startActivity(Intent)</code> always start a new activity and always call <code>onCreate()</code>, as suggested by the Android documentation?</p>