what is the correct usage of getActivity()
and getApplicationContext()
in fragment.
when getting an intent in fragment you use getActivity()
and someplaces you use getAppliationContext();
getActivity()
and getApplicationContext()
getActivity()
This method gives the context of the Activity. You can use it is like the yourActivity.this. The method getActivity()
is normally used in fragments to get the context of the activity in which they are inserted or inflated.
getApplicationContext()
Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just the current Activity.
For more Info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With