Skip to content

Commit 60a6b6c

Browse files
committed
Change Service to START_NOT_STICKY
Also throw the IllegalStateException if receiving null intent to start the service.
1 parent 33b559b commit 60a6b6c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/src/main/java/example/chatea/servicecamera/CameraService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public void onPictureTaken(byte[] data, Camera camera) {
9090

9191
@Override
9292
public int onStartCommand(Intent intent, int flags, int startId) {
93+
if (intent == null) {
94+
throw new IllegalStateException("Must start the service with intent");
95+
}
9396
switch (intent.getIntExtra(START_SERVICE_COMMAND, COMMAND_NONE)) {
9497
case COMMAND_START_RECORDING:
9598
handleStartRecordingCommand(intent);
@@ -101,7 +104,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
101104
throw new UnsupportedOperationException("Cannot start service with illegal commands");
102105
}
103106

104-
return START_STICKY;
107+
return START_NOT_STICKY;
105108
}
106109

107110
private void handleStartRecordingCommand(Intent intent) {

0 commit comments

Comments
 (0)