Skip to content

Commit

Permalink
Update MusicService.kt to FIX [4.0.1] Crash: com.doublesymmetry.track…
Browse files Browse the repository at this point in the history
…player.service.MusicService.startAndStopEmptyNotificationToAvoidANR

Update MusicService.kt to FIX [4.0.1] Crash: com.doublesymmetry.trackplayer.service.MusicService.startAndStopEmptyNotificationToAvoidANR 

doublesymmetry#2244 (reference)
  • Loading branch information
mayank-paryani authored Oct 18, 2024
1 parent 9ff32f0 commit e9995b5
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,17 @@ class MusicService : HeadlessJsTaskService() {
notificationBuilder.foregroundServiceBehavior = NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
}
val notification = notificationBuilder.build()
startForeground(EMPTY_NOTIFICATION_ID, notification)
@Suppress("DEPRECATION")
stopForeground(true)
try {
// reference exception catch of startForegroundIfNecessary function
startForeground(EMPTY_NOTIFICATION_ID, notification)
@Suppress("DEPRECATION")
stopForeground(true)
} catch (error: Exception) {
Timber.e(
"ForegroundServiceStartNotAllowedException: App tried to start a foreground Service when it was not allowed to do so.",
error
)
}
}

@MainThread
Expand Down

0 comments on commit e9995b5

Please sign in to comment.