0

I wonder what's the difference between Activity and Context? Because when I initialize WebView and getScreenSize,I replaced all the context with activity, and it works fine.

user3512988
  • 105
  • 1
  • 3
  • 7
  • 1
    Learn some more about object-oriented principles and inheritance. The `Activity` class indirectly extends `Context` therefore all Activities *ARE* Contexts. The reverse is not true however. – Squonk Aug 11 '14 at 00:36

2 Answers2

2

Activity extends Context, that's why it worked. Usually, when you need to pass a Context from your activity, you have to pass this.

This is what a Context is, according to the documentation.

Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It 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.

nstCactus
  • 5,141
  • 2
  • 30
  • 41
1

Context is 'like your activity'. Why what you did worked is because your activity tells you the context of the application. So then it knows where the webview displays.

someguy234
  • 559
  • 4
  • 17