Posts

Showing posts with the label getApplicationContext

Difference in-between getContext, getApplicationContext and getBaseContext. And When to use each of them?

What is Context actually? - context is the blueprint of activities and application, it can be used to get information regarding activity and application.  [ more on stackoverflow ] getContext - returns the context view of current or acive Activity. getApplicationContext - returns the context view of all the activities from the entire application. getBaseContext - returns the context view of an Activity to another Activity. to separate or specify those two context in an Activity BaseContext is used. When to use them: getContext - if your method only needs the context of current activity then we use get context. getApplicationContext - if your method if outside of an OnCreateMethod and you want to keep alive the context longer than getContext then you should go for getApplicationContext. getBaseContext - suppose you want to show a alert dialogue in your current activity. but the alert dialogue contain its own context so what to do? then you should go for getBaseContext otherwis...