Android Basic Examples


Example

Standard usage in Activity:

Context context = getApplicationContext();

Standard usage in Fragment:

Context context = getActivity().getApplicationContext(); 

this (when in a class that extends from Context, such as the Application, Activity, Service and IntentService classes)

TextView textView = new TextView(this);

another this example:

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);