My Java code contains the following lines:
Window window = getWindow();
View decor = window.getDecorView();
Context context = decor.getRootView().getContext();
Resources resources = context.getResources();
...
ActivityManager.TaskDescription description;
if (android.os.Build.VERSION.SDK_INT >= 28)
description = new ActivityManager.TaskDescription(
resources.getString(R.string.app_name),
R.drawable.app_icon,
ContextCompat.getColor(this, R.color.colorTaskBar));
else
//noinspection deprecation
description = new ActivityManager.TaskDescription(
resources.getString(R.string.app_name),
getBitmap(this, R.drawable.app_icon),
ContextCompat.getColor(this, R.color.colorTaskBar));
setTaskDescription(description);
My project build.gradle contains the following lines:
allprojects {
repositories {
google()
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
Since I have -Xlint:deprecation
option in my build.gradle file, I can find where I use deprecation in my code.
When I rebuild my project, I get the following warning:
[deprecation] TaskDescription(String,Bitmap,int) in TaskDescription has been deprecated
...and it points to use of
@Deprecated
public TaskDescription(String label, Bitmap icon, int colorPrimary)
Well, I am aware of that and as you can see in my Java code on top, I check version and I use
public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary)
for API 28+, as this version of TaskDescription
is available just from API 28.
So what am I suppose to do to get rid of the warning? I want to have my code clean and so I want to recode this part to have it 100% correct? What is wrong in my code?