getApplicationContext() 和 getActivity() 之间有什么区别this在安卓中?
之间有很多区别:
View.getContext() http://developer.android.com/reference/android/view/View.html#getContext%28%29:
返回视图当前运行的上下文。通常是当前活动的 Activity。
Activity.getApplicationContext(): http://developer.android.com/reference/android/content/ContextWrapper.html#getApplicationContext%28%29返回整个应用程序的上下文(所有活动都在其中运行的进程)。如果您需要与整个应用程序的生命周期相关联的上下文,而不仅仅是当前的 Activity,请使用此上下文而不是当前的 Activity 上下文。
ContextWrapper.getBaseContext(): http://developer.android.com/reference/android/content/ContextWrapper.html#getBaseContext%28%29如果您需要从另一个上下文中访问上下文,则可以使用 ContextWrapper。 ContextWrapper 内部引用的 Context 是通过 getBaseContext() 访问的。
另请检查:
https://stackoverflow.com/a/10641257/4018207 https://stackoverflow.com/a/10641257/4018207
https://developer.android.com/reference/android/view/View.html#getContext%28%29 https://developer.android.com/reference/android/view/View.html#getContext%28%29
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)