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。 



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章