Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import java.lang.Math.abs
// constants to make the code snippets work
const val currentPlayingIndex = 10

@Suppress("Unused")
@UnstableApi
// [START android_defaultpreloadmanager_MyTargetPreloadStatusControl]
class MyTargetPreloadStatusControl(
Expand Down Expand Up @@ -57,6 +58,7 @@ class MyTargetPreloadStatusControl(
}
// [END android_defaultpreloadmanager_MyTargetPreloadStatusControl]

@Suppress("Unused")
class PreloadManagerSnippetsKotlin {

class PreloadSnippetsActivity : AppCompatActivity() {
Expand All @@ -73,8 +75,6 @@ class PreloadManagerSnippetsKotlin {
val preloadManager = preloadManagerBuilder.build()
// [END android_defaultpreloadmanager_createPLM]

val player = preloadManagerBuilder.buildExoPlayer()

// [START android_defaultpreloadmanager_addMedia]
val initialMediaItems = pullMediaItemsFromService(/* count= */ 20)
for (index in 0 until initialMediaItems.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import androidx.annotation.Nullable;

@SuppressWarnings("Unused")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java all caps:
@SuppressWarnings("UNUSED")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just wanted to confirm here that it's @SuppressWarnings() in Java, but @Suppress() in Kotlin?

Copy link
Contributor Author

@asolovay asolovay Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually -- when I amend my commit, I still get the warning "Method 'doSomethingAndRelease()' is never used" for this Java file (but not for the Kotlin file).

Is there something I'm doing wrong with @SuppressWarnings()? Right now I have:

    @SuppressWarnings("UNUSED")
    // [START android_backgroundwork_wakelock_release_java]
    void doSomethingAndRelease() throws MyException {
        try {
            wakeLock.acquire();
            doTheWork();
        } finally {
            wakeLock.release();
        }
    }
    // [END android_backgroundwork_wakelock_release_java]
   

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks reasonable to me. Can you clarify where you are seeing the morning? Is this in Android Studio or a when you run a command line lint command? I can try your steps to reproduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in Android Studio, when I try to push the commit to GitHub--it pops up a screen saying "there are these warnings, are you sure you want to push?"

But when I try compiling the "misc" module, I get no warnings. So if the answer is "pay attention to that, don't worry about the warning you get when you push", I'm happy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we need to use @SuppressWarnings("unused") in Java. Android Studio lint only respects this if the "unused" is lowercase.

I'm thinking we should use lower case for both Kotlin: @Suppress("unused") and Java @SuppressWarnings("unused"). The capitalized version only work in Kotlin, so I would prefer to be consistent across languages by using lowercase.

public class WakeLockSnippetsJava extends Activity {

PowerManager.WakeLock wakeLock;
Expand All @@ -23,6 +24,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@SuppressWarnings("Unused")
// [START android_backgroundwork_wakelock_release_java]
void doSomethingAndRelease() throws MyException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.os.Bundle
import android.os.PowerManager

// Snippets for doc page go here
@Suppress("Unused")
class WakeLockSnippetsKotlin : Activity() {

// [START android_backgroundwork_wakelock_create_kotlin]
Expand Down