10

In any code, i guess, there are variables/method/classes that are really not used and maybe just there for show/just in case.

Anyway, How do i set Android Studio to stop giving me the 'yellow' error stripe marks in the scrollbar for unused variables. Although, i don't want to stop getting warnings all together.

A. K. Tolentino
  • 2,112
  • 3
  • 25
  • 33
  • Comment them out, or decorate with the "unused" annotation. http://stackoverflow.com/questions/1205995/what-is-the-list-of-valid-suppresswarnings-warning-names-in-java – Simon Jan 23 '14 at 06:29

3 Answers3

14

Fount it!

Right click the scroll bar > Customize Highlight Level > Configure inspections. You'll find an immense list, type-in the search field for unused then you'll see "Unused Symbol", unchecked it.

A. K. Tolentino
  • 2,112
  • 3
  • 25
  • 33
  • I tend to capture return values from methods all the time for inspection in the debugger, only to have these returned values flagged by lint as "unused". Rather than turn off the inspection for *all* unused return values and "unused" variables - I found the jetbrains help page that shows how to run an inspection and turn off the individual cases in the code. I like this better as I can leave the inspection turned on to catch unintentional coding "errors". http://www.jetbrains.com/help/idea/2016.2/suppressing-inspections.html – Jim Andreas Aug 27 '16 at 13:40
6

add SuppressWarnings annotation at the methods/variables/classes which are unused...

@SuppressWarnings("unused")
private String unusedString;

@SuppressWarnings("unused")
private void unusedMethod() {

}

@SuppressWarnings("unused")
private class UnUsedClass {

}
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
  • 1
    Oh my, i need to do it to every one of them? :( Nothing, though `File > Settings`, or similar? – A. K. Tolentino Jan 23 '14 at 07:02
  • The preferred technique. Some classes (like libraries) are designed for long-term use and may have methods and data are currently unnecessary. This allows us to turn off such warnings while still maintaining the Unused Symbol warnings in the bulk of our code (which can be very useful when optimizing other people's code). – SMBiggs Jun 30 '16 at 06:39
  • 2
    Now (on Android Studio 4.0.1, Build #AI-193.6911.18.40.6626763) I'm getting lint warnings saying "Redundant suppression" everywhere where I'm using the `@SuppressWarnings("unused")` annotation. This didn't happen before, by the way. When I remove the annotation, it shows a lint warning saying that the method/variable/class is never used. A (really dumb) workaround is adding a RedundantSuppression suppress warning annotation (like this: `@SuppressWarnings({"unused", "RedundantSuppression"})`). Is there a better way to do this? Is it a bug in recent Android Studio version, or is it config issue? – Vratislav Jindra Sep 14 '20 at 08:03
  • @VratislavJindra seems like it's a bug in the [Kotlin plugin/Kotlin project](https://youtrack.jetbrains.com/issue/KT-41293) that even affects your Java code. For me the behavior of adding `RedundantSuppression` additionally to `unused` suppression is annoying too. Until this isn't fixed I turned off the following Lint check `File > Settings > Inspections > General > Redundant Suppression`. Now the warning can be suppressed with `unused` only like before. – Danny Nov 12 '20 at 15:50
5

Highlight Level android studio

You can change highlighting level by clicking the button at the right corner in android studio.

Shabeer Ali
  • 903
  • 11
  • 20