YoKeyword/Fragmentation · critical · RuntimeException

must impl ISupportActivity!

Error message

 must impl ISupportActivity!

What it means

In onAttach(), the delegate requires the hosting Activity to implement ISupportActivity so it can bind the TransactionDelegate and FragmentActivity reference. If the attached activity does not implement it, a RuntimeException naming the activity class is thrown.

Solutions

  1. Extend SupportActivity for the host activity, or implement ISupportActivity with a SupportActivityDelegate in the activity.
  2. If the fragment cannot be hosted by a support activity, use a plain Fragment instead of SupportFragment.

Example fix

// before
public class HostActivity extends AppCompatActivity {
// after
public class HostActivity extends SupportActivity {
Defensive patterns

Strategy: validation

Validate before calling

if (!(hostActivity instanceof ISupportActivity)) {
    // refuse to add the SupportFragment here
}

Type guard

boolean canHostSupportFragment(Activity a) { return a instanceof ISupportActivity; }

Prevention

When it happens

Trigger: Attaching a SupportFragment to an Activity that does not implement ISupportActivity (e.g. a plain AppCompatActivity or a non-support container activity), whether via fragment transactions, dialogs, or viewpager hosting.

Common situations: Hosting a SupportFragment inside a regular activity (not SupportActivity); third-party container activities (e.g. image pickers, dialog hosts); forgetting to implement ISupportActivity when building a custom base activity.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of YoKeyword/Fragmentation@0394930a3e (2026-09-10). Data as JSON: /api/errors/2f575486a8794fd6. Report an issue: GitHub.

Appendix: source

Thrown at fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportFragmentDelegate.java:85

    /**
     * Perform some extra transactions.
     * 额外的事务:自定义Tag,添加SharedElement动画,操作非回退栈Fragment
     */
    public ExtraTransaction extraTransaction() {
        if (mTransactionDelegate == null)
            throw new RuntimeException(mFragment.getClass().getSimpleName() + " not attach!");

        return new ExtraTransaction.ExtraTransactionImpl<>((FragmentActivity) mSupport, mSupportF, mTransactionDelegate, false);
    }

    public void onAttach(Activity activity) {
        if (activity instanceof ISupportActivity) {
            this.mSupport = (ISupportActivity) activity;
            this._mActivity = (FragmentActivity) activity;
            mTransactionDelegate = mSupport.getSupportDelegate().getTransactionDelegate();
        } else {
            throw new RuntimeException(activity.getClass().getSimpleName() + " must impl ISupportActivity!");
        }
    }

    public void onCreate(@Nullable Bundle savedInstanceState) {
        getVisibleDelegate().onCreate(savedInstanceState);

        Bundle bundle = mFragment.getArguments();
        if (bundle != null) {
            mRootStatus = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_ROOT_STATUS, STATUS_UN_ROOT);
            mIsSharedElement = bundle.getBoolean(TransactionDelegate.FRAGMENTATION_ARG_IS_SHARED_ELEMENT, false);
            mContainerId = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CONTAINER);
            mReplaceMode = bundle.getBoolean(TransactionDelegate.FRAGMENTATION_ARG_REPLACE, false);
            mCustomEnterAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_ENTER_ANIM, Integer.MIN_VALUE);
            mCustomExitAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_EXIT_ANIM, Integer.MIN_VALUE);
            mCustomPopExitAnim = bundle.getInt(TransactionDelegate.FRAGMENTATION_ARG_CUSTOM_POP_EXIT_ANIM, Integer.MIN_VALUE);
        }

        if (savedInstanceState == null) {

View on GitHub (pinned to 0394930a3e)