您的位置:首页 > 移动开发

Context —— getApplicationContext()、getBaseContext()、this的区别

2016-09-05 14:52 399 查看
转自http://stackoverflow.com/questions/1026973/android-whats-the-difference-between-the-various-methods-to-get-a-context(英文)

getApplicationContext ()
方法在应用程序要被摧毁时,返回整个应用程序生命周期的应用上下文。

this
应用上下文返回activity的当前上下文,属于activity。当它被摧毁时,activity也被摧毁。

getBaseContext()
ContextWrapper
中的方法。

getbasecontext()返回由构造函数指定或setBaseContext()设置的上下文。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐