0

I just finished android beginner course from udacity and I was reading 'Starting Another Activity' from here.

http://developer.android.com/training/basics/firstapp/starting-activity.html

Developer.android says i need to pass context as the first parameter in the intent constructor.

After Reading this, What is 'Context' on Android?

I understand what is context but only in an abstract form.

TextView tv = new TextView(getContext());
ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);

In the above code, what does getContext actually do? Does the object 'tv' get some initial values? What are they? How do those values (if any) connect the object to rest of the app? What does connecting object to the rest of the app mean? I understand that it allows the object to access the resources of the app but how?

Doesn't inheritance takes care of connecting smaller app contents to the bigger app?

Also, how does 'this' keyword actually provide context?

Community
  • 1
  • 1
Siddhant
  • 143
  • 1
  • 13
  • 1
    That link you posted answered it pretty well for me, and I'm not an android dev. What did you not understand? "Context" *is* an abstract term. But the linked answer in your post tells you exactly how it's used in terms of android. – Vince Mar 18 '16 at 05:57
  • What happens to object 'tv' when we provide getContext to it's class constructors? What values does it get? – Siddhant Mar 18 '16 at 05:59
  • 1
    Looking at the source code, `TextView` uses the context to grab the current theme. But the context can be used for many things, as stated in the answer you posted. How it's used *depends on the component that's using it*. That last statement (the one i put in italics) is basically the definition of context: it depends on where it's being used. Check out the [API docs](http://developer.android.com/reference/android/content/Context.html) to see all possible ways it can be used. – Vince Mar 18 '16 at 06:06
  • Why does TextView requires current theme? The theme/style are defined in it's XML component. I understand that it's usage depends on the component using it but it would have been nice, if I could've found some examples as to what actually happens (behind the layers of abstraction) when context is being provided to an object. – Siddhant Mar 18 '16 at 06:10
  • Thats a different question, which should be asked in a different post. – Vince Mar 18 '16 at 06:11

0 Answers0