Reputation: 297
if i understand correctly, you use getContext()
to get the context of a view object. You use activity context or this
if you want to create a new object that exist as long as activity exist, if not the activity wont be destroyed and eventually lead to memory leaks. You use getApplicationContext()
if you want a context that is tied to the global lifecycle of the application and should be used wherever we need to create a object that exist beyond the current activity.
Is my understanding correct ?
But what is getBaseContext()
and where do you use it exactly.. One simple and solid example would be great
Upvotes: 3
Views: 1097
Reputation: 41
View.getContext() usually returns the context the view of current Activity. ContextWrapper.getBaseContext()is used while accessing a Context from within another context example Activity.
See at - [Difference between getContext() , getApplicationContext() , getBaseContext() and] "this"7]: Difference between getContext() , getApplicationContext() , getBaseContext() and "this"
Upvotes: 1