title: Cannot remove Fragment attached to a different FragmentManager. Fragment SupportMapFragment
body: <p>Android Studio 3.4.</p>
  
  <p>in gradle.properties:</p>
  
  <pre><code>android.useAndroidX=true
  android.enableJetifier=true
  </code></pre>
  
  <p>in <strong>app/build.gradle</strong>:</p>
  
  <pre><code>def AAVersion = '4.6.0'
  
  dependencies {
      annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
  
      implementation fileTree(dir: 'libs', include: ['*.jar'])
  
      implementation 'commons-io:commons-io:2.6'
      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'org.apache.commons:commons-lang3:3.8.1'
      implementation 'com.google.android.gms:play-services:4.3.23'
      implementation 'com.google.code.gson:gson:2.8.5'
      implementation 'com.nineoldandroids:library:2.4.0'
      implementation 'edu.vt.middleware:vt-password:3.1.2'
  
      implementation "org.androidannotations:androidannotations-api:$AAVersion"
  }
  </code></pre>
  
  <p>in fragment</p>
  
  <pre><code>import com.google.android.gms.maps.SupportMapFragment;
  import androidx.fragment.app.FragmentManager;
  
  
  public class AgentsFragmentMapTab extends androidx.fragment.app.Fragment {
  
  private SupportMapFragment mapFrag;
  
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
          try {
              if (mapFrag != null) {
                  FragmentManager fragmentManager = thisFragmentActivity.getSupportFragmentManager();
                  fragmentManager.beginTransaction().remove(mapFrag).commit();
                  thisFragmentActivity = null;
              }
          } catch (IllegalStateException e) {
          }
      }
  
  
  }
  </code></pre>
  
  <p>but I get runtime error in this line:</p>
  
  <pre><code>fragmentManager.beginTransaction().remove(mapFrag).commit();
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>( 6664): onDestroyView
  ( 6664): RootFragment#onDestroyView()
  (CATCHED)( 6664): Cannot remove Fragment attached to a different FragmentManager. Fragment SupportMapFragment{270ec77 (5411fd0b-1b45-40d3-b306-1452294a4734) id=0x7f0901d1} is already attached to a FragmentManager.
  (CATCHED)( 6664): java.lang.IllegalStateException: Cannot remove Fragment attached to a different FragmentManager. Fragment SupportMapFragment{270ec77 (5411fd0b-1b45-40d3-b306-1452294a4734) id=0x7f0901d1} is already attached to a FragmentManager.
  (CATCHED)( 6664):   at androidx.fragment.app.BackStackRecord.remove(BackStackRecord.java:188)
  (CATCHED)( 6664):   at com.myproject.AgentsFragmentMapTab.onDestroyView(AgentsFragmentMapTab.java:356)
  (CATCHED)( 6664):   at androidx.fragment.app.Fragment.performDestroyView(Fragment.java:2852)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:947)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1228)
  (CATCHED)( 6664):   at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2066)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1856)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1811)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1686)
  (CATCHED)( 6664):   at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299)
  (CATCHED)( 6664):   at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:230)
  (CATCHED)( 6664):   at androidx.viewpager.widget.ViewPager.setAdapter(ViewPager.java:513)
  (CATCHED)( 6664):   at md.qsystems.android.agents.SelectAgentMainFragment.removeViewPager(SelectAgentMainFragment.java:460)
  (CATCHED)( 6664):   at md.qsystems.android.agents.SelectAgentMainFragment.reloadAgents(SelectAgentMainFragment.java:553)
  (CATCHED)( 6664):   at md.qsystems.android.agents.SelectAgentMainFragment.access$000(SelectAgentMainFragment.java:54)
  (CATCHED)( 6664):   at md.qsystems.android.agents.SelectAgentMainFragment$1.onClick(SelectAgentMainFragment.java:114)
  (CATCHED)( 6664):   at android.view.View.performClick(View.java:5204)
  (CATCHED)( 6664):   at android.view.View$PerformClick.run(View.java:21153)
  (CATCHED)( 6664):   at android.os.Handler.handleCallback(Handler.java:739)
  (CATCHED)( 6664):   at android.os.Handler.dispatchMessage(Handler.java:95)
  (CATCHED)( 6664):   at android.os.Looper.loop(Looper.java:148)
  (CATCHED)( 6664):   at android.app.ActivityThread.main(ActivityThread.java:5417)
  (CATCHED)( 6664):   at java.lang.reflect.Method.invoke(Native Method)
  (CATCHED)( 6664):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  (CATCHED)( 6664):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  gment_)( 6664): reloadAgents_existing_fragments: []
  </code></pre>