Tencent/QMUI_Android · error · RuntimeException
Can not perform LatestVisitRecord, %s must be annotated by L
Error message
Can not perform LatestVisitRecord, %s must be annotated by LatestVisitRecord
What it means
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.
Source
Thrown at arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java:291
}
sLatestVisitFragmentUUid = mUUid;
if (!shouldPerformLatestVisitRecord()) {
QMUILatestVisit.getInstance(getContext()).clearFragmentLatestVisitRecord();
return;
}
Class<? extends QMUIFragment> cls = getClass();
LatestVisitRecord latestVisitRecord = cls.getAnnotation(LatestVisitRecord.class);
if (latestVisitRecord == null || (latestVisitRecord.onlyForDebug() && !QMUIConfig.DEBUG)) {
QMUILatestVisit.getInstance(getContext()).clearFragmentLatestVisitRecord();
return;
}
if (!activity.getClass().isAnnotationPresent(LatestVisitRecord.class)) {
throw new RuntimeException(String.format("Can not perform LatestVisitRecord, " +
"%s must be annotated by LatestVisitRecord", activity.getClass().getSimpleName()));
}
QMUILatestVisit.getInstance(getContext()).performLatestVisitRecord(this);
}
public final void onLatestVisitArgumentChanged() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.INITIALIZED) && sLatestVisitFragmentUUid == mUUid) {
checkLatestVisitRecord();
}
}
@Override
public void onCollectLatestVisitArgument(RecordArgumentEditor editor) {
}
@NullableView on GitHub (pinned to 026e7d4866)
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
Example fix
// before
public class MainActivity extends AppCompatActivity {}
// after
@LatestVisitRecord
public class MainActivity extends AppCompatActivity {} Defensive patterns
Strategy: validation
Validate before calling
if (getActivity() != null && getActivity().getClass().isAnnotationPresent(LatestVisitRecord.class)) { /* safe to proceed */ } Type guard
boolean hasLatestVisitRecord(Activity a) { return a != null && a.getClass().isAnnotationPresent(LatestVisitRecord.class); } Prevention
- 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
When it happens
Trigger: Calling onResume (or triggering onLatestVisitArgumentChanged) on a QMUIFragment whose host Activity class lacks the @LatestVisitRecord annotation, after the record was not cleared.
Common situations: 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.
Related errors
- Fragment(%s) not attached to Activity.
- Can not find the fragment container provider.
- requestCode can not be %s
- %s did not call through to super.shouldPreventSwipeBack()
- %s did not call through to super.onEnterAnimationStart(Anima
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/79aab4db71473154.
Report an issue: GitHub.