Android - what's the difference between the various methods to get a Context?
Posted
by Alnitak
on Stack Overflow
See other posts from Stack Overflow
or by Alnitak
Published on 2009-06-22T12:38:14Z
Indexed on
2010/03/20
8:51 UTC
Read the original article
Hit count: 271
android
|android-context
In various bits of Android code I've seen:
public class MyActivity extends Activity {
public void method() {
mContext = this; // since Activity extends Context
mContext = getApplicationContext();
mContext = getBaseContext();
}
}
However I can't find any decent explanation of which is preferable, and under what circumstances which should be used.
Pointers to documentation on this, and guidance about what might break if the wrong one is chosen, would be much appreciated.
© Stack Overflow or respective owner