title: Using onbackpressed() while using fragment containing map fragment
body: <p>I am working on a project where there are many fragments connected to a fragment manager.I want to implement onbackpressed method in my fragmentactivity so that i can go back to the previous fragement.</p>
  
  <p>The onbackpressedcode is shown below:</p>
  
  <pre><code>public void onBackPressed() {
  
                  int count = getSupportFragmentManager().getBackStackEntryCount();
  
                  if (count == 0) {
                      super.onBackPressed();
                      //additional code
                  } else {
  
  
                      getSupportFragmentManager().popBackStackImmediate();
                  }
  
              }
  </code></pre>
  
  <p>The issue is that there is a supportmapfragment in one of the fragment.There is a listview in that fragment .When i click an item in the listview it takes me to another fragment which contains details.When i press back i get an illegalstateexception as shown below:</p>
  
  <pre><code>10-27 13:31:26.039: E/AndroidRuntime(15458): FATAL EXCEPTION: main
  10-27 13:31:26.039: E/AndroidRuntime(15458): android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at com.igloo.fragments.ViewjobsFragment.onCreateView(ViewjobsFragment.java:123)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.BackStackRecord.popFromBackStack(BackStackRecord.java:764)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1527)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:494)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at com.igloo.marinaretail.UserMain.onBackPressed(UserMain.java:476)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.app.Activity.onKeyUp(Activity.java:1898)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.KeyEvent.dispatch(KeyEvent.java:1280)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.app.Activity.dispatchKeyEvent(Activity.java:2078)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1705)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2626)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2601)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1873)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.os.Handler.dispatchMessage(Handler.java:99)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.os.Looper.loop(Looper.java:130)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.app.ActivityThread.main(ActivityThread.java:3689)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at java.lang.reflect.Method.invokeNative(Native Method)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at java.lang.reflect.Method.invoke(Method.java:507)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at dalvik.system.NativeStart.main(Native Method)
  10-27 13:31:26.039: E/AndroidRuntime(15458): Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f06005e, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
  10-27 13:31:26.039: E/AndroidRuntime(15458):    ... 26 more
  </code></pre>
  
  <p>How do i prevent the above issue on pressing back.</p>
  
  <p>Also in the ondestroy method of the fragment containing the map i have the following code:</p>
  
  <pre><code>@Override
      public void onDestroy() {
  
          SupportMapFragment f = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
          if (f.isResumed()){ 
              getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit();
          }
  
          super.onDestroy();
      }
  </code></pre>
  
  <p><strong>How do i fix the back pressed issue?</strong></p>
  
  <p>Is there a way to check if the previous fragment in the stack is the fragment containing the supportmap?</p>