[转]this和getApplicationContext区别
this和getApplicationContext区别
public class MyActivity extends Activity {
public void method() {
mContext = this; // since Activity extends Context
mContext = getApplicationContext();
mContext = getBaseContext();
}
}
this 是因为Activity 扩展了Context,其生命周期是Activity 创建到销毁;
getApplicationContext 取得的Context是和Application关联的生命周期是应用的创建到销.