What's the difference between ActivityCompat a

2019-03-24 16:43发布

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条回答
贼婆χ
2楼-- · 2019-03-24 17:17

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):

enter image description here

查看更多
登录 后发表回答