title: Android: How to Clear Intent Stack While Using SingleTask
body: <p>I'm using Twitter <code>oAuth</code> library in my application. Users are logging in with ther Twitter accounts. </p>
  
  <p>In activity A, twitter login is available. When user logged in, I want to start activity B with no history. Here is my all stuff:</p>
  
  <p>Firstly, <code>Manifest.xml</code>, so I set <code>launchMode=singleTask</code> as Twitter api requested:</p>
  
  <pre><code>&lt;activity
      android:name=".A_Activity"
      android:label="@string/app_name"
      android:launchMode="singleTask"
      android:theme="@android:style/Theme.Black.NoTitleBar"&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;category android:name="android.intent.category.BROWSABLE" /&gt;
          &lt;data android:scheme="my_twitter_scheme" /&gt;
      &lt;/intent-filter&gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>Here is how I'm starting activity B:</p>
  
  <pre><code>Intent i = new Intent(A.this, B.class);
  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
  i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.startActivity(i);
  </code></pre>
  
  <p>Note: I'm calling activity B over BroadcastReceiver instance.</p>
  
  <p>When I logged in, my receivers starting activity B properly, but unfortunately when I pressed the back button, application turning back to activity A. </p>
  
  <p>I suppose it's about <code>launchMode</code> and as I said, Twitter needs that option. What am I doing wrong? Any help or suggestion (maybe about Twitter) would be great.</p>