What is different between getContext()
and getActivity()
from Fragment
in support library?
Do they always return the same obje
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.