{"record":{"id":"50fb84bcd0d892f4","repo":"YoKeyword/Fragmentation","slug":"must-extends-fragmentactivity-appcompatactivity","errorCode":null,"errorMessage":"Must extends FragmentActivity/AppCompatActivity","messagePattern":"Must extends FragmentActivity/AppCompatActivity","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportActivityDelegate.java","lineNumber":32,"sourceCode":"import me.yokeyword.fragmentation.anim.FragmentAnimator;\nimport me.yokeyword.fragmentation.debug.DebugStackDelegate;\nimport me.yokeyword.fragmentation.queue.Action;\n\npublic class SupportActivityDelegate {\n    private ISupportActivity mSupport;\n    private FragmentActivity mActivity;\n\n    boolean mPopMultipleNoAnim = false;\n    boolean mFragmentClickable = true;\n\n    private TransactionDelegate mTransactionDelegate;\n    private FragmentAnimator mFragmentAnimator;\n    private int mDefaultFragmentBackground = 0;\n    private DebugStackDelegate mDebugStackDelegate;\n\n    public SupportActivityDelegate(ISupportActivity support) {\n        if (!(support instanceof FragmentActivity))\n            throw new RuntimeException(\"Must extends FragmentActivity/AppCompatActivity\");\n        this.mSupport = support;\n        this.mActivity = (FragmentActivity) support;\n        this.mDebugStackDelegate = new DebugStackDelegate(this.mActivity);\n    }\n\n    /**\n     * Perform some extra transactions.\n     * 额外的事务：自定义Tag，添加SharedElement动画，操作非回退栈Fragment\n     */\n    public ExtraTransaction extraTransaction() {\n        return new ExtraTransaction.ExtraTransactionImpl<>((FragmentActivity) mSupport, getTopFragment(), getTransactionDelegate(), true);\n    }\n\n    public void onCreate(@Nullable Bundle savedInstanceState) {\n        mTransactionDelegate = getTransactionDelegate();\n        mFragmentAnimator = mSupport.onCreateFragmentAnimator();\n        mDebugStackDelegate.onCreate(Fragmentation.getDefault().getMode());\n    }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/YoKeyword/Fragmentation/blob/0394930a3e2368f210df31f2632fb89b9c44e121/fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportActivityDelegate.java#L14-L50","documentation":"SupportActivityDelegate wraps an ISupportActivity and requires it to be a FragmentActivity (AppCompatActivity extends it). The constructor throws a RuntimeException at initialization time if the passed activity is not a FragmentActivity, because the delegate casts and uses FragmentActivity APIs (getSupportFragmentManager) internally.","triggerScenarios":"Calling new SupportActivityDelegate(this) from an Activity that extends plain Activity (or any class not extending FragmentActivity), instead of extending SupportActivity or implementing ISupportActivity on a FragmentActivity subclass.","commonSituations":"Migrating a legacy app to fragmentation while keeping an Activity base class other than FragmentActivity; AppCompatActivity omitted from dependencies so devs extend android.app.Activity; custom base Activity hierarchies built on Activity.","solutions":["Make your Activity extend SupportActivity (me.yokeyword.fragmentation.SupportActivity).","Alternatively, extend AppCompatActivity (or FragmentActivity) and implement ISupportActivity by delegating to a SupportActivityDelegate.","Ensure the support library / AndroidX activity dependency is present so FragmentActivity is on the classpath."],"exampleFix":"// before\npublic class MainActivity extends Activity {\n// after\npublic class MainActivity extends SupportActivity {","handlingStrategy":"validation","validationCode":"if (!(this instanceof FragmentActivity)) {\n    throw new IllegalStateException(\"Activity hosting SupportActivityDelegate must extend FragmentActivity/AppCompatActivity\");\n}","typeGuard":"boolean isSupportHost(Activity a) { return a instanceof FragmentActivity && a instanceof ISupportActivity; }","tryCatchPattern":null,"preventionTips":["Always extend SupportActivity for any activity hosting support fragments.","Keep the FragmentActivity import from the support/AndroidX package.","Review custom activity base-class hierarchies for compliance before adopting fragmentation."],"tags":["android","activity","wrong-base-class"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"0394930a3e2368f210df31f2632fb89b9c44e121","analyzedAt":"2026-09-10T13:16:30.469Z","contentChangedAt":"2026-09-10T13:16:30.469Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}