android: null check intent in onStartCommand

For some reason the type annotations here show @NonNull but that is
actually false according to the documentation under service.

This may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY.
This commit is contained in:
Colin Edwards 2024-04-23 00:22:09 -05:00
parent cb6f61cf37
commit a0e9dfbec2
1 changed files with 2 additions and 2 deletions

View File

@ -133,11 +133,11 @@ public class Main extends Service implements Runnable {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (Objects.equals(intent.getAction(), SHUTDOWN_ACTION)) { if (intent != null && Objects.equals(intent.getAction(), SHUTDOWN_ACTION)) {
stop(); stop();
} else { } else {
start(); start();
if (intent.getBooleanExtra("wakelock", false)) if (intent != null && intent.getBooleanExtra("wakelock", false))
setWakelockEnabled(true); setWakelockEnabled(true);
} }
return START_STICKY; return START_STICKY;