What is Context in Android? Android is an 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.
Different ways of getting context
Usage of context
→ Loading common resources
→ Creating dynamic views
→ Displaying Toast messages
→ Launching Activities etc.
→ TextView tv = new TextView(getContext());
→ ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), …);
→ Toast toast = Toast.makeText(ActivityName.this, “Context Example”, Toast.LENGTH_LONG).show();
→ getApplicationContext().getContentResolver().query(uri, …);
Enjoy Coding and Share Knowledge