title: Android Activity Stack Replace Activity and Erase Top
body: <p>I am struggling to get this working but it hasnt been easy.
  I will try to clarify everthing, this might be a good question for other people.</p>
  
  <p>I have this activity stack right now:</p>
  
  <p>A -> B -> C -> D</p>
  
  <p>Then I receive a file using the bluetooth, I accept the file using the top menu bar, but remember my app with the whole stack is still running..
  Then again on the top menu bar, I open the file that I received, and I want it to create an activity E but with other information and with a new stack so would be:</p>
  
  <p>A -> B -> C -> D -> E</p>
  
  <p>Clicking the file the activity A is opened using this part of the code at AndroidManifest.xml:</p>
  
  <pre><code>         &lt;activity
              android:name="A"
  
              android:label="@string/title_activity_main_page"
              android:screenOrientation="portrait" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
                  &lt;data android:scheme="file" /&gt;
                  &lt;data android:host="*" /&gt;
                  &lt;data android:pathPattern=".*\\.sso" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&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="file" /&gt;
                  &lt;data android:mimeType="*/*" /&gt;
                  &lt;data android:pathPattern=".*\\.sso" /&gt;
                  &lt;data android:host="*" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  </code></pre>
  
  <p>In this case, when activity A is open by clicking the file, I create the activities calling each other.</p>
  
  <p>Right now this is how the stack gets constructed at the end:</p>
  
  <p>A -> B -> C -> D -> A -> B -> C -> D -> E</p>
  
  <p>And I want to create:</p>
  
  <p>A -> B -> C -> D -> E</p>
  
  <p>I don't know which tags to use, I tried to read the documentation about different flags but didn't found answer to this.. 
  Thanks alot in advance!</p>