title: Android close all fragments onBackPressed
body: <p>I have an activity with about 10 fragments in each fragment there is an AsyncTask with ProgressDialog I need  away to close  all fragments when I click back Button 
  it's closed but the ProgressDialog  still visible especially  when I transfer between fragments 
  here is the code I use</p>
  
  <pre><code> @Override
      public void onBackPressed() {
        if(fragmentManager!=null){
              for(int i = 0; i &lt; fragmentManager.getBackStackEntryCount(); ++i) {
                  fragmentManager.popBackStack();
              }}
                                   }
  </code></pre>
  
  <p>also when I debug I found that it enters onCreateView for each fragment I open when I press back button although I use <code>transaction.replace</code> method to transfer between fragments. </p>