LibreTube/app/src/main/java/com/github/libretube/services/ClosingService.kt

28 lines
775 B
Kotlin
Raw Normal View History

2022-06-28 20:02:26 +05:30
package com.github.libretube.services
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
2022-09-08 22:11:57 +05:30
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
2022-06-28 20:02:26 +05:30
class ClosingService : Service() {
override fun onBind(intent: Intent?): IBinder? {
return null
}
// Handle application closing
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
2022-07-30 16:03:01 +05:30
// destroy the player notification when the app gets destroyed
2022-06-28 20:02:26 +05:30
val nManager = this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
2022-07-30 16:03:01 +05:30
nManager.cancel(PLAYER_NOTIFICATION_ID)
2022-06-28 20:02:26 +05:30
// Destroy the service
stopSelf()
}
}