What's the difference between ActivityCompat and ContextCompat?

核能气质少年 提交于 2019-12-09 08:30:41

问题


I'm trying to use the Android camera, for API 23 or above, it requires asking for permission at runtime. According to the documentation, I can accomplish that using, ActivityCompat or ContextCompat. I don't understand what are the difference between the two and their trade-offs.

Thank you for time.


回答1:


I don't understand what are the difference between the two and their trade-offs

There's no trade-off really. Not sure why they wrote so - checkSelfPermission() is a method of ContextCompat and ActivityCompat is subclass (child) of ContextCompat so you can pass either one whenever object of ContextCompat class is required.

Inheritance hierarchy (docs):



来源:https://stackoverflow.com/questions/38229842/whats-the-difference-between-activitycompat-and-contextcompat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!