What is the difference between getContext() , getApplicationContext() , getBaseContext() , and “this“?
Though this is simple question I am unable to understand the basic difference between them. Please give some easy examples if possible.
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.
View.getContext(): Returns the context the view is currently running in. Usually the currently active Activity.Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running insideof). 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.
ContextWrapper.getBaseContext(): If you need access to a Context from within another context, you use a ContextWrapper. TheContext referred to from inside that ContextWrapper is accessed via
getBaseContext().