由于SDK 23上已经弃用了onAttach(Activity)方法,那么在Fragment生命周期中检查Activity是否实现接口的最佳方法是什么?
这段代码已经不再正确,将来甚至可能会被删除。
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof OnInterfaceOfFragmentListener)
mCallback = (OnInterfaceOfFragmentListener) activity;
else
throw new RuntimeException("OnInterfaceOfFragmentListener not implemented in activity");
}
onAttach(Context)
方法... 但是... 通过这种方法传递的上下文将是 Activity... - Selvin