When I'm using list view and I have a custom Base Adapter class, I get different text color in list view when base adapter is instantiated by getApplicationContext
and classname.this
.
By getApplicationContext
I get white text color but classname.this
is black. Can anyone explain it for me?

- 5,753
- 72
- 57
- 129

- 1,023
- 2
- 13
- 29
-
2see [here](http://stackoverflow.com/questions/5018545/getapplication-vs-getapplicationcontext) – Gunaseelan Apr 22 '13 at 07:19
-
may be you have applied a different theme to your specific activity then the entire application. This could cause the difference in styles based on which context is used. – Shiv Apr 22 '13 at 07:35
-
I actually use android:theme="@style/Theme.VPI" in all my activty – Misagh Aghakhani Apr 22 '13 at 07:44
2 Answers
ActivityName.this refers to activity context. getApplicationContext () refers to the application context.
Most of the times it is better to use activity context.
Check the answer provided by commonsware. Has a detail explanation on the topic.
When to call activity context OR application context?
Quote form the above link
Here are reasons why not to use getApplicationContext() wherever you go:
It's not a complete Context, supporting everything that Activity does. Various things you will try to do with this Context will fail, mostly related to the GUI.
It can create memory leaks, if the Context from getApplicationContext() holds onto something created by your calls on it that you don't clean up. With an Activity, if it holds onto something, once the Activity gets garbage collected, everything else flushes out too. The Application object remains for the lifetime of your process.

- 1
- 1

- 132,755
- 26
- 225
- 256
-
Thank you very much but really I could not catch why the text color is different in both context – Misagh Aghakhani Apr 22 '13 at 07:37
-
just read the point 1 in the answer. maybe the reason. show us some code. – Raghunandan Apr 22 '13 at 07:37
-
Yes, you are right maybe I should read context reference carefully – Misagh Aghakhani Apr 22 '13 at 07:40
-
@Shiv checked the link. it comes down to point 1 in the above answer. may be the reason – Raghunandan Apr 22 '13 at 07:47
Basically they are both instances of Context, but the difference is application instance is tied to the lifecycle of the application, while the Activity instance is tied to the lifecycle of an Activity. Thus, they have access to different information about the application environment...
EDIT
In finding your answer it will help you Android Holo Light styling changes depending on chosen context