From 5d768331452837ddc9ca823fde7e7b7e952fe019 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 30 May 2020 15:50:43 +0200 Subject: [PATCH] use the proper way of stopping the music service --- app/src/main/AndroidManifest.xml | 1 - .../com/simplemobiletools/musicplayer/helpers/Constants.kt | 1 - .../musicplayer/receivers/NotificationDismissedReceiver.kt | 7 ++++--- .../simplemobiletools/musicplayer/services/MusicService.kt | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b1c1352..b53ea11a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -123,7 +123,6 @@ - diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt index 13cb8a27..32d0c58f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt @@ -32,7 +32,6 @@ const val REMOVE_CURRENT_SONG = PATH + "REMOVE_CURRENT_SONG" const val REMOVE_SONG_IDS = PATH + "REMOVE_SONG_IDS" const val BROADCAST_STATUS = PATH + "BROADCAST_STATUS" const val NOTIFICATION_DISMISSED = PATH + "NOTIFICATION_DISMISSED" -const val STOP_SERVICE = PATH + "STOP_SERVICE" const val NEW_SONG = "NEW_SONG" const val IS_PLAYING = "IS_PLAYING" diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/receivers/NotificationDismissedReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/receivers/NotificationDismissedReceiver.kt index 0e6bd567..4d0cafb7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/receivers/NotificationDismissedReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/receivers/NotificationDismissedReceiver.kt @@ -3,11 +3,12 @@ package com.simplemobiletools.musicplayer.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import com.simplemobiletools.musicplayer.extensions.sendIntent -import com.simplemobiletools.musicplayer.helpers.STOP_SERVICE +import com.simplemobiletools.musicplayer.services.MusicService class NotificationDismissedReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - context.sendIntent(STOP_SERVICE) + Intent(context, MusicService::class.java).apply { + context.stopService(this) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index d7190c4a..cc743bdb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -131,7 +131,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } val action = intent.action - if (isOreoPlus() && action != NEXT && action != PREVIOUS && action != PLAYPAUSE && action != STOP_SERVICE) { + if (isOreoPlus() && action != NEXT && action != PREVIOUS && action != PLAYPAUSE) { setupFakeNotification() } @@ -158,7 +158,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr START_SLEEP_TIMER -> startSleepTimer() STOP_SLEEP_TIMER -> stopSleepTimer() BROADCAST_STATUS -> broadcastPlayerStatus() - STOP_SERVICE -> stopSelf() } MediaButtonReceiver.handleIntent(mMediaSession!!, intent)