kotlin suppress warning deprecated for Android

AndroidWarningsKotlin

Android Problem Overview


In my Kotlin Android project, I am using a function that has been deprecated starting from api 23, which is quite recent. So I need a way to disable those deprecated warnings. Is there an easy way to do so?

Android Solutions


Solution 1 - Android

Use @Suppress annotation with argument "DEPRECATION":

@Suppress("DEPRECATION")
someObject.theDeprecatedFunction()

Instead of a single statement, you can also mark a function, a class or a file (@file:Suppress("DEPRECATION") in its beginning) with the annotation to suppress all the deprecation warnings issued there.

In IntelliJ IDEA this can also be done through Alt+Enter menu with caret placed on code with deprecation warning.

Solution 2 - Android

In Kotlin

> @SuppressWarnings

is changed to

> @Suppress

For removing the strike through deprecation warnings you should add,

 @Suppress("DEPRECATION")

to remove the warning from the super method. By adding

@Suppress("OverridingDeprecatedMember")

The warning of the function will get removed. So, the complete annotation will be;

@Suppress("OverridingDeprecatedMember", "DEPRECATION")

As an additional note the deprecation should be written as "DEPRECATION" ( use capital letters)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionloloof64View Question on Stackoverflow
Solution 1 - AndroidhotkeyView Answer on Stackoverflow
Solution 2 - AndroidManoj PerumarathView Answer on Stackoverflow