Are Activity and Context the same, or are there differences?
When should I have a method pass an Activity, and when a Context?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I understand:
Context is the Base Object. So every Activity same as Application derives from Context. This means that every Activity and every
ApplicationIS aContext;From
developer.android.comActivityAnd Application
An Application context lasts, as long as your app is alive, while the Activity context dies with your Activity (it is not valid after
onDestroyof that Activity).So if you need the Context across Activities (i.e. in a Singleton) you will be better off using an Application context.
Usually on Android Framework methods where a context is expected, it makes no difference which one you pass. But be always aware of MemoryLeaks if you’re keeping long-living References to a Context