Skip to content
Closed
Changes from all commits
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 @@ -204,7 +204,13 @@ class ForegroundService : Service() {
if (::foregroundServiceStatus.isInitialized) {
isCorrectlyStopped = foregroundServiceStatus.isCorrectlyStopped()
}
val allowAutoRestart = foregroundTaskOptions.allowAutoRestart
// Guard against UninitializedPropertyAccessException when Android
// destroys the service before onStartCommand() initializes the options
// (same pattern as the foregroundServiceStatus check above).
var allowAutoRestart = false
if (::foregroundTaskOptions.isInitialized) {
allowAutoRestart = foregroundTaskOptions.allowAutoRestart
}
if (allowAutoRestart && !isCorrectlyStopped && !ForegroundServiceUtils.isSetStopWithTaskFlag(this)) {
Log.e(TAG, "The service will be restarted after 5 seconds because it wasn't properly stopped.")
RestartReceiver.setRestartAlarm(this, 5000)
Expand Down