diff --git a/app/src/main/java/com/OxGames/Pluvia/MainActivity.kt b/app/src/main/java/com/OxGames/Pluvia/MainActivity.kt index 2e094b8..6181fd6 100644 --- a/app/src/main/java/com/OxGames/Pluvia/MainActivity.kt +++ b/app/src/main/java/com/OxGames/Pluvia/MainActivity.kt @@ -67,7 +67,6 @@ class MainActivity : ComponentActivity() { } private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = { - SteamService.stop() finishAndRemoveTask() } diff --git a/app/src/main/java/com/OxGames/Pluvia/service/NotificationHelper.kt b/app/src/main/java/com/OxGames/Pluvia/service/NotificationHelper.kt index e215167..07870f2 100644 --- a/app/src/main/java/com/OxGames/Pluvia/service/NotificationHelper.kt +++ b/app/src/main/java/com/OxGames/Pluvia/service/NotificationHelper.kt @@ -71,7 +71,7 @@ class NotificationHelper(private val context: Context) { val stopIntent = Intent(context, SteamService::class.java).apply { action = ACTION_EXIT } - val stopPendingIntent = PendingIntent.getService( + val stopPendingIntent = PendingIntent.getForegroundService( context, 0, stopIntent, diff --git a/app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt b/app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt index ba2b5b7..6782ff4 100644 --- a/app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt +++ b/app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt @@ -190,6 +190,10 @@ class SteamService : Service(), IChallengeUrlChanged { private val dbScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) + private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = { + SteamService.stop() + } + companion object { const val MAX_SIMULTANEOUS_PICS_REQUESTS = 50 const val PICS_CHANGE_CHECK_DELAY = 60000L @@ -1096,6 +1100,8 @@ class SteamService : Service(), IChallengeUrlChanged { super.onCreate() instance = this + PluviaApp.events.on(onEndProcess) + notificationHelper = NotificationHelper(applicationContext) // To view log messages in android logcat properly @@ -1117,6 +1123,7 @@ class SteamService : Service(), IChallengeUrlChanged { // Notification intents when (intent?.action) { NotificationHelper.ACTION_EXIT -> { + Timber.d("Exiting app via notification intent") PluviaApp.events.emit(AndroidEvent.EndProcess) return START_NOT_STICKY } @@ -1291,6 +1298,7 @@ class SteamService : Service(), IChallengeUrlChanged { isStopping = false retryAttempt = 0 + PluviaApp.events.off(onEndProcess) PluviaApp.events.clearAllListenersOf>() }