getApplicationContext()、getBaseContext()、getApplication()、getParent()
有什么区别:
getApplicationContext()
getBasecontext()
getApplication()
getParent()
你能详细说明一下吗一个简单的例子?
What is the difference between:
getApplicationContext()
getBasecontext()
getApplication()
getParent()
Can you elaborate with one simple example?
getApplicationContext()
应用程序上下文与应用程序相关联,并且在整个生命周期中始终保持不变。不应该使用
getBasecontext()
,只需使用Context
而不是它,它与 Activity 关联,并且可以在 Activity 销毁时销毁。getApplicationContext()
Application context is associated with the Application and will always be the same throughout the life cycle.getBasecontext()
should not be used, just useContext
instead of it which is associated with the activity and can be destroyed when the activity is destroyed.