title: Android deep linking - Back stack
body: <p>I am trying to implement deep linking in my Android application. I have been following <a href="http://developer.android.com/training/app-indexing/deep-linking.html">this guide</a>. I have an Android Activity that is started from and intent-filter in the Android manifest:</p>
  
  <pre><code>&lt;activity
      android:name=".MyActivity"
      android:parentActivityName=".MainActivity" &gt;
      &lt;intent-filter android:label="@string/filter_title_deep_link"&gt;
          &lt;action android:name="android.intent.action.VIEW" /&gt;
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
          &lt;data android:scheme="com.example" /&gt;
      &lt;/intent-filter&gt;
      &lt;meta-data
          android:name="android.support.PARENT_ACTIVITY"
          android:value=".MainActivity"/&gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>I am spawning this intent from adb:</p>
  
  <pre><code>adb shell am start -W -a android.intent.action.VIEW -d "com.example://test" com.example
  </code></pre>
  
  <p>The activity is being created with the correct intent data and runs as expected. However, on press of the back button, the application exits. I was expecting the back stack to be built with <code>MainActivity</code>, as specified by <code>parentActivityName</code> in the Android manifest. Obviously this is not the case.</p>
  
  <p>How can I add a parent activity to the back stack in this case?</p>
  
  <p>I wondered if I could use a <code>TaskStackBuilder</code> as shown <a href="http://developer.android.com/training/implementing-navigation/temporal.html">here</a> in the context of notifications, but wasn't sure how it would work.</p>
  
  <p>Perhaps I should have an intermediate Activity to build the main activity using something like:</p>
  
  <pre><code>TaskStackBuilder.create(this)
                  .addParentStack(MyActivity.class)
                  .addNextIntent(new Intent(this, MyActivity.class))
                  .startActivities();
  </code></pre>
  
  <p>?</p>