Reputation: 19287
I don't know when to use someActivityClass.this
and when to use getApplicationContext()
to set as a Context
! What is the difference ? When do I have to use the first option and when do I have to use the second option ?
Upvotes: 1
Views: 76
Reputation: 5260
Its very small but very important difference in android application code.
android.content.Context
Context is an abstract class whose allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
1. getApplicationContext(): Application context is attached to the application's life-cycle.
2. LoginActivity.this : Activity context is live with the Activity's life-cycle and can be destroyed if the activity's onDestroy.
3. getBaseContext() : This Context is available to widgets and Views.
For more detail :
http://developer.android.com/reference/android/content/Context.html
When to call activity context OR application context?
Difference between getContext() , getApplicationContext() , getBaseContext() and "this"
Getting the Application Context
Upvotes: 2