title: Android finish() StartActivityForResult not working
body: <p>I have a problem in Android with the finish() function:</p>
  
  <p>I am trying to obtain the following behavior: when the user lunches the application for the first time, I want to start a wizard procedure. I am using a PageViewer with different fragmets. I want that the application closes, if the user presses the back button while it is in the first page.</p>
  
  <p>Here what I did:</p>
  
  <p>In the <strong>main activity</strong> I check if the user has started the application for the first time. If this is the case, then I start a <strong>new activity</strong> (the wizard)</p>
  
  <pre><code>if(firstTime) {
      // here activity is the main activity
      Intent i = new Intent(activity, Wizard.class);
      activity.startActivityForResult(i,0);
  }
  </code></pre>
  
  <p><strong>In the wizard activity class</strong> I override the onBackPressed method:</p>
  
  <pre><code>@Override
  public void onBackPressed(){
      if(pager.getCurrentItem() == 0) {
          setResult(5);
          finish();
      } else{
          // code
      }
  }
  </code></pre>
  
  <p>When finish() is called, Android invokes the onActivityResult method of the parent activity (the main activity):</p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data){
      if(resultCode == 5) {
          finish()
      } 
  }
  </code></pre>
  
  <p>What I expect is the application to be closed. What I get is that Android calls onResume and, then, onCreate methods, starting the wizard from the beginning. Then, if from this new wizard I press back again, the application closes as expected.</p>
  
  <p>Thanks for any help!</p>