YoKeyword/Fragmentation · critical · RuntimeException

Must extends FragmentActivity/AppCompatActivity

Error message

Must extends FragmentActivity/AppCompatActivity

What it means

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.

Solutions

  1. Make your Activity extend SupportActivity (me.yokeyword.fragmentation.SupportActivity).
  2. Alternatively, extend AppCompatActivity (or FragmentActivity) and implement ISupportActivity by delegating to a SupportActivityDelegate.
  3. Ensure the support library / AndroidX activity dependency is present so FragmentActivity is on the classpath.

Example fix

// before
public class MainActivity extends Activity {
// after
public class MainActivity extends SupportActivity {
Defensive patterns

Strategy: validation

Validate before calling

if (!(this instanceof FragmentActivity)) {
    throw new IllegalStateException("Activity hosting SupportActivityDelegate must extend FragmentActivity/AppCompatActivity");
}

Type guard

boolean isSupportHost(Activity a) { return a instanceof FragmentActivity && a instanceof ISupportActivity; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at fragmentation_core/src/main/java/me/yokeyword/fragmentation/SupportActivityDelegate.java:32

import me.yokeyword.fragmentation.anim.FragmentAnimator;
import me.yokeyword.fragmentation.debug.DebugStackDelegate;
import me.yokeyword.fragmentation.queue.Action;

public class SupportActivityDelegate {
    private ISupportActivity mSupport;
    private FragmentActivity mActivity;

    boolean mPopMultipleNoAnim = false;
    boolean mFragmentClickable = true;

    private TransactionDelegate mTransactionDelegate;
    private FragmentAnimator mFragmentAnimator;
    private int mDefaultFragmentBackground = 0;
    private DebugStackDelegate mDebugStackDelegate;

    public SupportActivityDelegate(ISupportActivity support) {
        if (!(support instanceof FragmentActivity))
            throw new RuntimeException("Must extends FragmentActivity/AppCompatActivity");
        this.mSupport = support;
        this.mActivity = (FragmentActivity) support;
        this.mDebugStackDelegate = new DebugStackDelegate(this.mActivity);
    }

    /**
     * Perform some extra transactions.
     * 额外的事务:自定义Tag,添加SharedElement动画,操作非回退栈Fragment
     */
    public ExtraTransaction extraTransaction() {
        return new ExtraTransaction.ExtraTransactionImpl<>((FragmentActivity) mSupport, getTopFragment(), getTransactionDelegate(), true);
    }

    public void onCreate(@Nullable Bundle savedInstanceState) {
        mTransactionDelegate = getTransactionDelegate();
        mFragmentAnimator = mSupport.onCreateFragmentAnimator();
        mDebugStackDelegate.onCreate(Fragmentation.getDefault().getMode());
    }

View on GitHub (pinned to 0394930a3e)