Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic explanation of Context in android

"If you can't explain it to a six year old, you don't understand it yourself." — Albert Einstein

After reading about a context on the android developer web site and various other places on the web I am still a bit fuzzy. In this line of code I am a bit confused what the parameter really means. I am not ashamed to get a 6 year old answer....

TextView textView = new TextView(getBaseContext());

Thanks

like image 414
Mike Casa Avatar asked Jun 23 '11 21:06

Mike Casa


People also ask

What is context in Android and how it is used?

A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. An Android app has activities. Context is like a handle to the environment your application is currently running in. The activity object inherits the Context object.

What is context in app?

A Context provides access to information about the application state. It provides Activities, Fragments, and Services access to resource files, images, themes/styles, and external directory locations.


1 Answers

  • Sea for a fish,
  • sky for a bird,
  • nest for a birdie,
  • a rabbit hole for a rabbit,
  • the space where a javax.swing.JComponent is drawn.

A context, is a way to describe the ether/environment an entity lives in and how to access other stuff living in this environment, interact with it.

:) First attempt of poetic answer for stack over flow ;)

At least, a 6 years old child would get the first four analogies.

More pragmatically, we can find different way to conceptualize what a context is, but it remains what the methods of this interface can offer as a set of services.

like image 73
Snicolas Avatar answered Oct 24 '22 03:10

Snicolas