DEFINE DIFFERENT KIND OF CONTEXT IN ANDROID

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
 2294  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Define different kind of context in android

    Context defines the current state of application or object. Context provides access to things such as creating new activity instance, access databases, start a service, etc. You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this when in the activity class.

    //Creating ui instance
    ImageButton button = new ImageButton(getContext());
    //creating adapter
    ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
    //querying content provider
    getApplicationContext().getContentResolver().query(uri, ...);
    //start activity. Here this means activity context
    Intent intent = new Intent(this, SecondActivity.class);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!