{"record":{"id":"79aab4db71473154","repo":"Tencent/QMUI_Android","slug":"can-not-perform-latestvisitrecord-s-must-be-anno","errorCode":null,"errorMessage":"Can not perform LatestVisitRecord, %s must be annotated by LatestVisitRecord","messagePattern":"Can not perform LatestVisitRecord, (.+?) must be annotated by LatestVisitRecord","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java","lineNumber":291,"sourceCode":"        }\n\n        sLatestVisitFragmentUUid = mUUid;\n\n        if (!shouldPerformLatestVisitRecord()) {\n            QMUILatestVisit.getInstance(getContext()).clearFragmentLatestVisitRecord();\n            return;\n        }\n\n        Class<? extends QMUIFragment> cls = getClass();\n        LatestVisitRecord latestVisitRecord = cls.getAnnotation(LatestVisitRecord.class);\n        if (latestVisitRecord == null || (latestVisitRecord.onlyForDebug() && !QMUIConfig.DEBUG)) {\n            QMUILatestVisit.getInstance(getContext()).clearFragmentLatestVisitRecord();\n            return;\n        }\n\n\n        if (!activity.getClass().isAnnotationPresent(LatestVisitRecord.class)) {\n            throw new RuntimeException(String.format(\"Can not perform LatestVisitRecord, \" +\n                    \"%s must be annotated by LatestVisitRecord\", activity.getClass().getSimpleName()));\n        }\n        QMUILatestVisit.getInstance(getContext()).performLatestVisitRecord(this);\n    }\n\n    public final void onLatestVisitArgumentChanged() {\n        if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.INITIALIZED) && sLatestVisitFragmentUUid == mUUid) {\n            checkLatestVisitRecord();\n        }\n    }\n\n    @Override\n    public void onCollectLatestVisitArgument(RecordArgumentEditor editor) {\n\n    }\n\n\n    @Nullable","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java#L273-L309","documentation":"QMUIFragment throws this when it tries to perform a LatestVisitRecord but the host Activity class is not annotated with @LatestVisitRecord. The library requires the annotation as an explicit opt-in so it only tracks fragment visit records for activities that declare support for it.","triggerScenarios":"Calling onResume (or triggering onLatestVisitArgumentChanged) on a QMUIFragment whose host Activity class lacks the @LatestVisitRecord annotation, after the record was not cleared.","commonSituations":"Adding a QMUIFragment to a plain AppCompatActivity (or any activity not annotated) and forgetting the annotation; migrating an existing activity to QMUI arch without reading the LatestVisitRecord docs.","solutions":["Annotate the host Activity class with @LatestVisitRecord","If tracking is unwanted, ensure the code path that clears the record runs before this check (see clearFragmentLatestVisitRecord branch)","Update the activity to extend the QMUI arch base activity and add the annotation in the same change"],"exampleFix":"// before\npublic class MainActivity extends AppCompatActivity {}\n// after\n@LatestVisitRecord\npublic class MainActivity extends AppCompatActivity {}","handlingStrategy":"validation","validationCode":"if (getActivity() != null && getActivity().getClass().isAnnotationPresent(LatestVisitRecord.class)) { /* safe to proceed */ }","typeGuard":"boolean hasLatestVisitRecord(Activity a) { return a != null && a.getClass().isAnnotationPresent(LatestVisitRecord.class); }","tryCatchPattern":null,"preventionTips":["Always annotate activities hosting QMUIFragments with @LatestVisitRecord if visit tracking is used","Centralize base activity classes so annotations are inherited conventions","Review new activity creation checklist for required QMUI annotations"],"tags":["android","annotation","runtime"],"backgroundTag":"missing-required-annotation","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"}