How would you resolve "error: method does not override or implement a method from a supertype"?

How would you resolve "error: method does not override or implement a method from a supertype"?

这是导致错误的部分

代码在 ListFragment

    @Override
    public void onAttach(AppCompatActivity activity) {
        super.onAttach(activity);
        this.listener = (SampleListListener)activity;

根据developer.android.com: "onAttach(Activity activity) 此方法已在 API 级别 24.1.0 中弃用。参见 onAttach(Context)。 我应该找到另一种方法来实现它吗?

参数应该是Context而不是Activity

@Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }