title: Finish parent and current activity in Android
body: <p>I have 3 activities. Activity A which leads to activity B, which in turn can go back to activity A or start activity C. However, if I press back in activity C the app should close.</p>
  
  <p>To sum up:</p>
  
  <ul>
  <li>Activity A starts activity B</li>
  <li>Pressing <strong>Back</strong> on activity B should lead to A</li>
  <li>Activity B starts activity C</li>
  <li>Pressing <strong>Back</strong> on activity C should close the app</li>
  </ul>
  
  <p>How should I go from activity B to C? This code currently gives me a NullPointerException on the last line:</p>
  
  <pre><code>Intent intent=new Intent(ActivityB.this, ActivityC.class);
  startActivity(intent);
  ActivityB.this.finish();
  ActivityB.this.getParent().finish();
  </code></pre>
  
  <p>If I switch the last two lines I also get a null pointer.</p>