Vote Up 0 Vote Down

difference between this and context in android

Whats the difference between "this" and "context" ?
flag

Answers


Vote Up 0 Vote Down
this-represents present activity..context- it holds other activity or applications context. ..
flag | link |
Vote Up 0 Vote Down
context means the area whr the activity execute.... N this for current activity area.
e.g. when we use the intents, we transfer the control from curent activity to another... n there we use 'this' in the place context in the syntanx of intent. ..
flag | link |
Vote Up 0 Vote Down
Context keyword
As the name suggests, its 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, package/application) You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class). Typical uses of context:

1)Creating New objects: Creating new views, adapters, listeners: TextView tv = new TextView(getContext()); ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
2) Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences: context.getSystemService(LAYOUT_INFLATER_SERVICE) getApplicationContext().getSharedPreferences(*name*, *mode*);
3)Accessing Components Implicitly: Regarding content providers, broadcasts, intent getApplicationContext().getContentResolver().query(uri, ...);

this keyword
if you have an Activity you can use this because: this is the current instance of a class an Activity is inherits from the class "Context" so you can use your current Activity as a Context.
this -> refers to the context of current activity
flag | link |
Vote Up 0 Vote Down
This pointer always points to current class object app context will points to entire process there is only one app context if you wnat to use some control whose life time is through out your application life time then go for context else this pointer.
flag | link |

Your Answer

Login before answering

Login with facebook