{"record":{"id":"a703a6be1f2cb93a","repo":"Tencent/QMUI_Android","slug":"can-not-find-the-fragment-container-provider","errorCode":null,"errorMessage":"Can not find the fragment container provider.","messagePattern":"Can not find the fragment container provider\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java","lineNumber":382,"sourceCode":"     * fragment D and destroy fragment C. Now you are in fragment D, if you want call\n     * {@link #popBackStack()} to back to B, what the animation should be? Sometimes we hope run\n     * animation generated by transition B->C, but sometimes we hope run animation generated by\n     * transition C->D. this why second parameter exists.\n     *\n     * @param fragment                      new fragment to start\n     * @param useNewTransitionConfigWhenPop if true, use animation generated by transition C->D,\n     *                                      else, use animation generated by transition B->C\n     */\n    public int startFragmentAndDestroyCurrent(QMUIFragment fragment,\n                                                 boolean useNewTransitionConfigWhenPop) {\n        if (!checkStateLoss(\"startFragmentAndDestroyCurrent\")) {\n            return -1;\n        }\n\n        QMUIFragmentContainerProvider provider = findFragmentContainerProvider(true);\n        if (provider == null) {\n            if (QMUIConfig.DEBUG) {\n                throw new RuntimeException(\"Can not find the fragment container provider.\");\n            } else {\n                Log.d(TAG, \"Can not find the fragment container provider.\");\n                return -1;\n            }\n        }\n\n        if(provider.getContainerFragmentManager().isDestroyed()){\n            return -1;\n        }\n\n        QMUIFragment.TransitionConfig transitionConfig = fragment.onFetchTransitionConfig();\n        String tagName = fragment.getClass().getSimpleName();\n        FragmentManager fragmentManager = provider.getContainerFragmentManager();\n        FragmentTransaction transaction = fragmentManager.beginTransaction()\n                .setCustomAnimations(\n                        transitionConfig.enter, transitionConfig.exit,\n                        transitionConfig.popenter, transitionConfig.popout)\n                .setPrimaryNavigationFragment(null)","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java#L364-L400","documentation":"startFragmentAndDestroyCurrent needs a QMUIFragmentContainerProvider (normally the hosting QMUIFragmentActivity) to obtain the container FragmentManager. When none is found the library throws in DEBUG builds (and only logs/returns -1 in release).","triggerScenarios":"Calling startFragmentAndDestroyCurrent from a QMUIFragment hosted in an activity that does not implement QMUIFragmentContainerProvider, or before the fragment is attached.","commonSituations":"Hosting QMUIFragment inside a non-QMUI activity (plain FragmentActivity/AppCompatActivity), nested fragments whose parent activity chain lacks the provider, calling from a detached fragment.","solutions":["Host fragments inside QMUIFragmentActivity (which implements QMUIFragmentContainerProvider)","Make the host activity implement QMUIFragmentContainerProvider and return a valid FragmentManager/container id","Ensure the fragment is attached before calling startFragmentAndDestroyCurrent"],"exampleFix":"// before\npublic class MainActivity extends AppCompatActivity {}\n// after\npublic class MainActivity extends QMUIFragmentActivity {}","handlingStrategy":"validation","validationCode":"if (isAdded() && getActivity() instanceof QMUIFragmentContainerProvider) { startFragmentAndDestroyCurrent(target); }","typeGuard":"boolean hasContainerProvider(Fragment f) { return f.getActivity() instanceof QMUIFragmentContainerProvider; }","tryCatchPattern":null,"preventionTips":["Use QMUIFragmentActivity as the standard host","Implement QMUIFragmentContainerProvider in custom host activities","Only navigate from attached fragments"],"tags":["android","navigation"],"backgroundTag":"resource-not-found","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}