title: Fragment remove and commit on onPause() throws exception
body: <p>In my application there is a fragment activity containing three tabs(map,list,settings). I have put remove and commit at onPause() method of map tab(extends fragment). When i toggle between tabs, it is working fine but when I move to next page(next activity) and come back, it throws nullpointer exception.</p>
  
  <p>Because when I switch to next activity, onPause() map fragment has been removed and committed and when comes back it found it null and throws exception. I am unable to figure out, where to place my onPause() method code or how to init fragment again on restart or resume.</p>
  
  <p>public class LocatorMainActivity extends FragmentActivity  {</p>
  
  <pre><code>public class MapSectionFragment extends Fragment {
      GoogleMap map;
  
      public MapSectionFragment() {
  
      }
  
  
      /*
       * (non-Javadoc)
       * 
       * @see android.support.v4.app.Fragment#onDestroyView()
       */
      @Override
      public void onDestroyView() {
          // TODO Auto-generated method stub
          super.onDestroyView();
  
          Log.e("", "onDestroyView");
  
          /*try{
  
              Fragment fragment = (getFragmentManager()
                      .findFragmentById(R.id.map));
  
              ft = getFragmentManager()
                      .beginTransaction();
  
  
              //ft.addToBackStack(null);
              ft.remove(fragment);
              ft.commit();
              //getFragmentManager().executePendingTransactions();
              //ft.commitAllowingStateLoss();
  
          }catch(Exception e){
              Log.e("", "Exception::" + e.toString());
          }*/
      }
  
      @Override
      public void onPause(){
  
          super.onPause();
          Log.e("", "onPause"); 
  
          try{
  
              Fragment fragment = (getFragmentManager()
                      .findFragmentById(R.id.map));
  
              ft = getFragmentManager()
                      .beginTransaction();
  
              //if(ft.isAddToBackStackAllowed()){
                  //ft.hide(fragment);
              if(ft.isAddToBackStackAllowed()){
  
                  Log.e("", "back stack allowed"); 
                  ft.remove(fragment);
                  //ft.addToBackStack(getTag());
                  //ft.addToBackStack(null);
                  ft.commit();
              }
  
              //}
  
              //getFragmentManager().executePendingTransactions();
              //ft.commitAllowingStateLoss();
  
          }catch(Exception e){
              Log.e("", "Exception::" + e.toString());
          }
      }
  
  
  /*  
      @Override
      public void onResume(){
  
          super.onResume();
          Log.e("inner", "onResume"); 
  
      }*/
  
  
      @Override
      public void onStop() {
          super.onStop();
          Log.e("inner", "onStop"); 
  
          //mReturningWithResult = false;
  
      }
  
      View rootView = null;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          //code
          });
          return rootView;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Please suggest me where I am wrong. 
  Thanks. </p>