title: Destroy/ finish previous activities from the current fragment in android
body: <p>I have been developing this application for quite a while now and came up with this bug in the app. Initially when the application loads for the first time, it starts from the <strong>home activity.</strong> Then the user interaction will navigate application to <strong>activity1</strong> which uses <strong>fragment1.</strong> The fragment1 has a button. If the user clicks on that button,the activity1 calls finish() and loads <strong>activity2</strong> by calling startActivity().Also when the user clicks on the hardware back button from the fargment1, the application returns to the Home activity. </p>
  
  <p>So the real issue here is that, when I am at activity2 and finish() the activity the application will show the Home activity. But i want to completely close the application on pressing back from the activity2.</p>
  
  <p>The following is the code which starts the activity2 form the fragment1:</p>
  
  <pre><code>Intent intent = new Intent(context, Activity2.class);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(intent);
                  ((Activity)context).finish();
  </code></pre>
  
  <p>I get that the Home activity has never been finish()-ed.</p>
  
  <p>So how do I destroy the activity1 and home activity on navigating to the activity2, and make the activity2 only remaining activity in the application?</p>
  
  <p>Thanks in advance.</p>