javaandroidandroid-studioandroid-service

Must be one of: Service.START_STICKY_COMPATIBILITY, Service.START_STICKY, Service.START_NOT_STICKY, Service.START_REDELIVER_INTENT


When I have:

public int onStartCommand(Intent intent, int flags, int startId) { 
    try { 
        player.start(); 
        isRunning = true; 
    } 
    catch(Exception e) { 
        isRunning = false; 
        player.stop(); 
    } 

    return 1;
} 

I get the following "error" for return 1:

Must be one of: Service.START_STICKY_COMPATIBILITY, Service.START_STICKY, Service.START_NOT_STICKY, Service.START_REDELIVER_INTENT

How do I fix it?


Solution

  • If you meant to return START_STICKY, which is of type int equal to 1, from onStartCommand(...), you did nothing wrong. This is your IDE that prompts it.

    You can ignore the warning. In case of absence of other errors, your code will compile and run successfully.

    If the warning is annoying, return START_STICKY instead.