What is difference between this
and getContext()
, when I say this
I mean this
within an Activity
.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
getContext()
is not defined in an Activity. It's used in aView
(orView
subclass) to get a reference to the enclosing context (an Activity).There is no difference. When you are in an Activity, getContext() will return this. This is because an Activity is a context!
In general there are two type of classes. Ones that extend
ContextWrapper
class (Activity
,Service
,Application
) and those that do not extend it (likeView
).If class extends
ContextWrapper
then you can usethis
asContext
. Such classes normally do not havegetContext()
method.Those classes that do not extend
ContextWrapper
but still save and useContext
normally exposegetContext()
function. And you cannot usethis
asContext
in such cases.And these two cases are mutually exclusive. At least I don't recall classes that extend
ContextWrapper
and havegetContext
at the same time.