title: How to clear activity stack trace on back press event?
body: <p>I have created an application that has multiple pages and navigation from one to another represents a crucial flow. I don't want the user to be able to press the back button and escape the activity without first warning him and then finally deleting all stack trace such that when the activity is launched again it starts afresh.</p>
  
  <p>As of yet I have been using something similar to the function below :</p>
  
  <pre><code>    @Override
      public void onBackPressed() 
      {
          this.finish(); 
          Intent int1= new Intent(this, Home.class);
          int1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
          startActivity(int1);
          super.onBackPressed();
      }
  </code></pre>
  
  <p>But sometimes when after quitting the application when I launch it again it restarts from some random page or the one from where I quit the application (basically not the home screen from where it is expected to start)</p>
  
  <p>I cannot think of a cleaner way to quit the application other than clearing all the previous activity flags as described in the code.
  Any help on the above is appreciated! </p>
  
  <p>EDIT :</p>
  
  <p>Anytime during the flow of my activity if the user presses the back button, I want the control to be thrown back to the main page (clearing all the previous activity stack traces). Such that in case someone re-lanches the application it will re start normally from the main page.</p>