What is different between getContext and getActivity from Fragment in support library?

前端 未结 8 731
深忆病人
深忆病人 2020-12-02 15:39

What is different between getContext() and getActivity() from Fragment in support library?

Do they always return the same obje

8条回答
  •  自闭症患者
    2020-12-02 15:59

    getContext():- Returns the context the view is currently running in. Usually the currently active Activity. getContext() is not defined in an Activity. It's used in a View (or View subclass) to get a reference to the enclosing context (an Activity).

    getActivity():- This method gives the context of the Activity. You can use it is like the yourActivity.this. getActivity() is normally used in fragments to get the context of the activity in which they are inserted or inflated.

提交回复
热议问题