title: Activity launched from broadcast receiver , keeps in recently tasks in spite of have been finished
body: <p>I've an issue with two activities that I can't solve:</p>
  
  <p>I have an A activity that programs an alarm with the alarm manager, in 3 seconds the alarm receiver launches a B activity that only has a finish button.</p>
  
  <p>If I program the alarm manager from A and finish this activity pressing the back button, in 3 seconds the B activity appears. All normal. The problem is the following: if I re-open the application by the launcher, the system starts A activity, but if I start the application by long pressing the home button (recently used tasks) I always open the B activity.
  I need that when I finish B activity , if I reopen the application from anywhere, the A activity should open. </p>
  
  <p>I've tried to add noHistory to activity B, but the problem continues.</p>
  
  <p>Here is the code of A activity:</p>
  
  <pre><code>public class ActivityA extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_a);
  
      Button b=(Button) findViewById(R.id.initTimer);
      b.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              programTimer();
          }
      });
  }
  
  private void programTimer() {
      AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      Intent intent = new Intent(this, AlarmReciver.class);
      PendingIntent pIntent = PendingIntent.getBroadcast(this, 1, intent,  PendingIntent.FLAG_CANCEL_CURRENT);
      manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3000 , pIntent);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>B activity:</p>
  
  <pre><code>public class ActivityB extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_b);
  
      Button button= (Button) findViewById(R.id.bFinish);
      button.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              finish();
          }
      });
  }
  </code></pre>
  
  <p>}</p>
  
  <p>AlarmReciver:</p>
  
  <pre><code>public class AlarmReciver extends android.content.BroadcastReceiver {
  private static final String DEBUG_TAG="ReceptorAlarma";
  @Override
  public void onReceive(Context context, android.content.Intent intent) {     
      //lanzar activity
      Intent i = new Intent(context, ActivityB.class); 
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(i);       
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Manifest:</p>
  
  <pre><code>    &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".ActivityA"
          android:label="@string/title_activity_activity" &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;/activity&gt;
  
      &lt;activity android:name=".ActivityB"&gt;            
      &lt;/activity&gt;
  
      &lt;receiver android:name=".AlarmReciver" &gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>thanks for your time.</p>