9

I'm new to Android. Can someone explain me the concept of Context class/Object. What it is? What it will be used for? Why Context class?

3
  • I think, this place is not meant for this kind of general questions. I suggest you to be more specific.
    – Ömer
    May 20, 2010 at 6:41
  • 4
    Given the state of the Android documention, this is not a general question. Jan 23, 2011 at 8:41
  • this might help others. Get clear idea of concept from here Context Concept Dec 3, 2014 at 12:05

4 Answers 4

5

Have you seen the android developer's guide? it will answer your questions:

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.

A Context has a lot of functions, but as a developer, you primarily use it to load and access application resources.

5

In programming Android applications, you will hardly ever need to use the Context class directly (not possible at all since Context is abstract), but you will need the child classes that derive from it like Activity, Service etc. You might want to look these up.

1
  • That was really helpful, the API documentation completely misses this point.
    – Yiannis
    Sep 7, 2011 at 10:43
1

You can think of Context, like the end-user-interface that will use that code. When you are in a class you can know based on Context if you have visual screen(Activity), or a running service(Service).

To compare against some other programming example, you can think of Context is equal to Console App, GUI App, or even Applet.

1

I hope if you read this source code you will have answer for the problems:

http://www.devdaily.com/java/jwarehouse/android/core/java/android/content/Context.java.shtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.