【Android】关于上下文的种种传说

Contextandroid

  1. 中文直译为“上下文”
  2. SDK中对其说明以下

  Interface to global information about an application environment. This is an abstract class whose implementationapp

  is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls ide

  for application-level operations such as launching activities, broadcasting and receiving intents, etc测试

 

 

 

看一段测试代码this

private Context mContext;
    public void method() { 
        mContext = this;
        mContext = MainActivity.this; 
        mContext = getApplicationContext(); 
        mContext = getBaseContext(); 
        Log.v("huangc","####  mContext="+ this );
        Log.v("huangc","####  MainActivity.this="+ MainActivity.this );
        Log.v("huangc","####  getApplicationContext()="+getApplicationContext() );
        Log.v("huangc","####  getBaseContext()="+ getBaseContext());
     }

看日志输出spa

####  mContext=com.example.test4intent.MainActivity@302ffdcb
####  MainActivity.this=com.example.test4intent.MainActivity@302ffdcb
####  getApplicationContext()=android.app.Application@39c519a8
####  getBaseContext()=android.app.ContextImpl@26ad4cc1

可见大多数状况下.net

【1】 this == MainActivity.this日志

【2】this != getApplicationContext() != getBaseContext()code

 

 

 

参考文档orm

http://blog.csdn.net/qinjuning/article/details/7310620

相关文章
相关标签/搜索