From b071654688de17fee7c04d628be300e77b04ffa0 Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Wed, 27 May 2020 18:18:38 -0300 Subject: [PATCH] NY-9844 [AN]: DownloadFileService IllegalStateException on stopService fix --- .../communicator/data/DownloadFileService.kt | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt index ece5081bd9..d33b077baf 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt @@ -50,16 +50,13 @@ class DownloadFileService : Service() { } fun stopServıce(context: Context) { - context.startService(getStopIntent(context)) + context.stopService(getStopIntent(context)) } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent != null && START_DOWNLOAD_FOREGROUND_ACTION == intent.action) { startForeground(START_DOWNLOAD_FOREGROUND_ACTION) - return START_NOT_STICKY - } else if (intent != null && STOP_DOWNLOAD_FOREGROUND_ACTION == intent.action) { - stopForeground(STOP_DOWNLOAD_FOREGROUND_ACTION) } return START_NOT_STICKY @@ -84,17 +81,18 @@ class DownloadFileService : Service() { } } - @Synchronized - private fun stopForeground(action: String?) { - if (action != null && STOP_DOWNLOAD_FOREGROUND_ACTION == action) { - stopForeground(true) - mStarted = false - stopSelf() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - mNotificationHelper.clearNotificationById(ONGOING_NOTIFICATION_ID) - } + private fun clearNotification() { + stopForeground(true) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + mNotificationHelper.clearNotificationById(ONGOING_NOTIFICATION_ID) } } + override fun onDestroy() { + mStarted = false + clearNotification() + super.onDestroy() + } + override fun onBind(intent: Intent?) = null } \ No newline at end of file -- GitLab