title: finish activity in which a pending intent starts
body: <p>In my app, i created a custom notification that contain a button that show recent apps(instead of home button long press)</p>
  
  <p>when user open main activity and press home button to go to home screen then drag the notification drawer and click on the button:</p>
  
  <p>Desired result is that the recent apps are shown and the main activity is one of the recent apps.</p>
  
  <p>Actual result is that the recent apps are shown but the main activity is not in them and the main activity resumes.</p>
  
  <p>My code to start "RecentApps (is a dummy class that show recent apps)" class with pending intent</p>
  
  <pre><code>    Intent recentAppIntent = new Intent(getBaseContext(), RecentApps.class);
      PendingIntent pendingrecentAppIntent = PendingIntent.getActivity(getBaseContext(), 1, recentAppIntent, 0);
      notificationView.setOnClickPendingIntent(R.id.recentAppButt, pendingrecentAppIntent);
  </code></pre>
  
  <p>I think that the problem is getBaseContext, so when the main activity is alive and not finished the recent apps are shown but with context is the main activity.</p>
  
  <p>I tried getApplication and getApplicationContext but not working.</p>
  
  <p>I also tried to use flags for "recentAppIntent" but it is not working, It is a half solution to use </p>
  
  <pre><code>recentAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  </code></pre>
  
  <p>but it not what i need.</p>
  
  <p>So, my question is "How to finish the main activity in which the pending intent starts".</p>
  
  <p>Thanks in advance, Mostafa</p>