Android Fragment.java中的getActivity()方法解析

废话不多说,看源码:

/**
     * Return the {@link FragmentActivity} this fragment is currently associated with.
     * May return {@code null} if the fragment is associated with a {@link Context}
     * instead.
     *
     * @see #requireActivity()
     */
    @Nullable
    final public FragmentActivity getActivity() {
        return mHost == null ? null : (FragmentActivity) mHost.getActivity();
    }

大概意思为:返回一个和此fragment绑定的FragmentActivity或者其子类的实例。相反,如果此fragment绑定的是一个context的话,可能会返回null。 



猜你喜欢

转载自blog.csdn.net/callmeMrLu/article/details/80192272