I want to know when to use ContextCompact
class in an application. Basically what is it used for and when to use it? I have read developers site, it says Cont
ContextCompat
is a class for replacing some work with base context.
For example if you used before something like
getContext().getColor(R.color.black);
Now its deprecated since android 6.0 (API 22+) so you should use:
getContext().getColor(R.color.black,theme);
or use ContextCompat
which fill theme automatically depends on your Context
's theme:
ContextCompat.getColor(getContext(),R.color.black)
Same thing with getDrawable
Also ContextCompat
contains other methods for functional of API 22+ such as checking permissions or adding multiple activity to stack