getApplicationContext()、getBaseContext()、getApplication()、getParent() [英] getApplicationContext(), getBaseContext(), getApplication(), getParent()

查看:22
本文介绍了getApplicationContext()、getBaseContext()、getApplication()、getParent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别:

  1. getApplicationContext()
  2. getBasecontext()
  3. getApplication()
  4. getParent()

你能举一个简单的例子来详细说明吗?

Can you elaborate with one simple example?

推荐答案

getApplicationContext() 应用程序上下文与应用程序相关联,并且在整个生命周期中始终相同.

getApplicationContext() Application context is associated with the Application and will always be the same throughout the life cycle.

getBasecontext() 不应该使用,只需使用 Context 代替它,它与活动相关联,可以在活动销毁时销毁.

getBasecontext() should not be used, just use Context instead of it which is associated with the activity and can be destroyed when the activity is destroyed.

这篇关于getApplicationContext()、getBaseContext()、getApplication()、getParent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆