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 2012/12/19 5:03 UTC
Read the original article Hit count: 114

Filed under:
|

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

Related posts about android

Related posts about android-context