在我的android项目中:
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
在build.gradle中:
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'
我的片段
import androidx.fragment.app.FragmentManager;
com.google.android.gms.maps
public class AgentsFragmentMapTab extends Fragment {
private SupportMapFragment mapFrag;
@Override
public void onDestroyView() {
super.onDestroyView();
try {
if (mapFrag != null) {
FragmentManager fm = thisFragmentActivity.getSupportFragmentManager();
fm.beginTransaction().remove(mapFrag).commit();
thisFragmentActivity = null;
}
} catch (IllegalStateException e) {
}
}
此行中的运行时错误:
fm.beginTransaction().remove(mapFrag).commit();
错误消息:
Cannot remove Fragment attached to a different FragmentManager. Fragment SupportMapFragment{9b891cc (9a1b8486-fe26-4e78-8628-b7647fae31ff) id=0x7f0901d1} is already attached to a FragmentManager.
java.lang.IllegalStateException: Cannot remove Fragment attached to a different FragmentManager. Fragment SupportMapFragment{9b891cc (9a1b8486-fe26-4e78-8628-b7647fae31ff) id=0x7f0901d1} is already attached to a FragmentManager.
at androidx.fragment.app.BackStackRecord.remove(BackStackRecord.java:188)
at com.myproject.map.AgentsFragmentMapTab.onDestroyView(AgentsFragmentMapTab.java:355)
at androidx.fragment.app.Fragment.performDestroyView(Fragment.java:2852)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:947)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1228)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2066)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1856)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1811)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1686)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:230)
at androidx.viewpager.widget.ViewPager.setAdapter(ViewPager.java:513)
at com.myproject.agents.SelectAgentMainFragment.removeViewPager(SelectAgentMainFragment.java:459)
at com.myproject.agents.SelectAgentMainFragment.reloadAgents(SelectAgentMainFragment.java:550)
at com.myproject.agents.SelectAgentMainFragment.access$000(SelectAgentMainFragment.java:55)
at com.myproject.agents.SelectAgentMainFragment$1.onClick(SelectAgentMainFragment.java:113)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)