getApplicationContext(), getBaseContext(), getApplication(), getParent()

getApplicationContext() Application context is associated with the Applicaition and will always be the same throughout the life cycle. getBasecontext() should not be used, just use Context instead of it which is associated with the activity and could possible be destroyed when the activity is destroyed. getApplication() is available to Activity and Services only. Although in … Read more

What is the difference between Activity and Context?

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 Application IS a Context; From developer.android.com Activity java.lang.Object ↳ android.content.Context ↳ android.content.ContextWrapper ↳ android.view.ContextThemeWrapper ↳ android.app.Activity And Application java.lang.Object ↳ android.content.Context ↳ android.content.ContextWrapper ↳ android.app.Application An Application context lasts, … Read more

get Context in non-Activity class [duplicate]

If your class is non-activity class, and creating an instance of it from the activiy, you can pass an instance of context via constructor of the later as follows: class YourNonActivityClass{ // variable to hold context private Context context; //save the context recievied via constructor in a local variable public YourNonActivityClass(Context context){ this.context=context; } } … Read more

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

Toast and Intent, both requires reference to context. And getApplication, getApplicationContext, LoginActivity.this and getBaseContext, they all offer reference to the context. Now the thing confuses is the declaration of different contexts and their specific-usage. To make things simple, you should count two types of context available in the Android framework. Application Context Activity Context Application … Read more