all: use compat when stopping foreground services
Use ServiceCompat.stopForeground instead of stopForeground. This is preliminary preparation for Android 13. I can only change SDK versions however when the Android Gradle Plugin makes a new release though.
This commit is contained in:
@@ -245,11 +245,12 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
|
||||
}
|
||||
|
||||
private fun updateSortMenu(displayMode: DisplayMode, isVisible: (Int) -> Boolean) {
|
||||
val sortItem = requireNotNull(sortItem) { "Cannot update sort menu while detached" }
|
||||
val sortMenu =
|
||||
requireNotNull(sortItem?.subMenu) { "Cannot update sort menu while detached" }
|
||||
|
||||
val toHighlight = homeModel.getSortForDisplay(displayMode)
|
||||
|
||||
for (option in sortItem.subMenu) {
|
||||
for (option in sortMenu) {
|
||||
if (option.itemId == toHighlight.itemId) {
|
||||
option.isChecked = true
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.ServiceCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -136,7 +137,7 @@ class IndexerService : Service(), Indexer.Callback {
|
||||
|
||||
private fun stopForegroundSession() {
|
||||
if (isForeground) {
|
||||
stopForeground(true)
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
isForeground = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.media.AudioManager
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.ServiceCompat
|
||||
import com.google.android.exoplayer2.C
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
@@ -159,7 +160,7 @@ class PlaybackService :
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
|
||||
stopForeground(true)
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
isForeground = false
|
||||
|
||||
// Pause just in case this destruction was unexpected.
|
||||
@@ -356,7 +357,7 @@ class PlaybackService :
|
||||
|
||||
/** Stop the foreground state and hide the notification */
|
||||
private fun stopAndSave() {
|
||||
stopForeground(true)
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
isForeground = false
|
||||
saveScope.launch { playbackManager.saveState(this@PlaybackService) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user