title: Restarting Android app programmatically
body: <p>This is a follow up question to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/2470870/force-application-to-restart-on-first-activity">Force application to restart on first activity</a></p>
  
  <p>I am trying to restart my application from a fragment like that:</p>
  
  <pre><code>    Toast.makeText(getActivity(), "Restarting app", Toast.LENGTH_SHORT).show();
      Intent i = getActivity().getBaseContext().getPackageManager()
  .getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName() );
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(i);
      getActivity().finish();
  </code></pre>
  
  <p>The code does nothing. The <code>finish()</code> is the only thing working for some reason. If I remove the <code>finish()</code>, nothing happens. Why is that?</p>