Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context in Android Programming [duplicate]

Tags:

android

Possible Duplicate:
What is Context in Android?

Can anybody please tell me about the "context" term used in android. I wonder what exactly this means because this is something i used to see at lots of places.

I found it being a Class :- "Interface to global information about an application environment" but I am not quite clear regarding it still by now.

for Instance: public GetCurrentLocation(Context context) { this.context = context; }

Thanks, david

like image 597
David Brown Avatar asked Sep 03 '10 12:09

David Brown


People also ask

What is context in Android programming?

Definition. it's the context of current state of the application/object. It lets newly-created objects understand what has been going on. Typically, you call it to get information regarding another part of your program (activity and package/application).

What is the difference between activity context and application context?

Application Context: It is the application and we are present in Application. For example - MyApplication(which extends Application class). It is an instance of MyApplication only. Activity Context: It is the activity and we are present in Activity.

What is the difference between activity and context?

An Application context lasts, as long as your app is alive, while the Activity context dies with your Activity (it is not valid after onDestroy of that Activity).


1 Answers

I have answered it here

this.context = context is written confusingly. Another way to write the same:

public class LocationClass {

private Context context_belonging_to_class = null;

// ..

public GetCurrentLocation(Context context_from_call_entity) {
  context_belonging_to_class = context_from_calling_entity; // initializing context variable
}

// ..

}
like image 56
Sameer Segal Avatar answered Sep 23 '22 04:09

Sameer Segal