This is stackoverflow on the answer of a netizen:
Original address: Http://stackoverflow.com/questions/3572463/what-is-context-in-android
As the name suggests, its the context of the application/object. It lets newly created objects understand what have been going on. Typically you-call it-get information regarding another part of the Your program (activity, Package/application)
You can get the context by invoking getApplicationContext()
, getContext()
, getBaseContext()
or (if in the this
activity Class).
Typical uses of context:
-
Creating new objects : Creating new views, adapters, listeners:
1 TextView TV = TextView (GetContext ( )); 2 listadapter adapter = new
Simplecursoradapter (Getapplicationcontext (), ...);
-
accessing Common Resources : Services like Layout_inflater_service, sharedpreferences :
1 context.getsystemservice (Layout_ Inflater_service) 2 Getapplicationcontext (). Getsharedpreferences (* name*, *mode*);
-
Accessing components implicitly : Regarding content providers, broadcasts, intent
getApplicationContext().getContentResolver().query(uri, ...);
What is the context in Android and how does it use