Skip to content

Commit 0460e99

Browse files
authored
Merge pull request #157 from oxters168/stop-fix
Fix "Exit" not terminating service when app is not in focus
2 parents 475bc4a + 43a92b5 commit 0460e99

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

app/src/main/java/com/OxGames/Pluvia/MainActivity.kt

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class MainActivity : ComponentActivity() {
6767
}
6868

6969
private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = {
70-
SteamService.stop()
7170
finishAndRemoveTask()
7271
}
7372

app/src/main/java/com/OxGames/Pluvia/service/NotificationHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class NotificationHelper(private val context: Context) {
7171
val stopIntent = Intent(context, SteamService::class.java).apply {
7272
action = ACTION_EXIT
7373
}
74-
val stopPendingIntent = PendingIntent.getService(
74+
val stopPendingIntent = PendingIntent.getForegroundService(
7575
context,
7676
0,
7777
stopIntent,

app/src/main/java/com/OxGames/Pluvia/service/SteamService.kt

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ class SteamService : Service(), IChallengeUrlChanged {
190190
private val dbScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
191191
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
192192

193+
private val onEndProcess: (AndroidEvent.EndProcess) -> Unit = {
194+
SteamService.stop()
195+
}
196+
193197
companion object {
194198
const val MAX_SIMULTANEOUS_PICS_REQUESTS = 50
195199
const val PICS_CHANGE_CHECK_DELAY = 60000L
@@ -1096,6 +1100,8 @@ class SteamService : Service(), IChallengeUrlChanged {
10961100
super.onCreate()
10971101
instance = this
10981102

1103+
PluviaApp.events.on<AndroidEvent.EndProcess, Unit>(onEndProcess)
1104+
10991105
notificationHelper = NotificationHelper(applicationContext)
11001106

11011107
// To view log messages in android logcat properly
@@ -1117,6 +1123,7 @@ class SteamService : Service(), IChallengeUrlChanged {
11171123
// Notification intents
11181124
when (intent?.action) {
11191125
NotificationHelper.ACTION_EXIT -> {
1126+
Timber.d("Exiting app via notification intent")
11201127
PluviaApp.events.emit(AndroidEvent.EndProcess)
11211128
return START_NOT_STICKY
11221129
}
@@ -1291,6 +1298,7 @@ class SteamService : Service(), IChallengeUrlChanged {
12911298
isStopping = false
12921299
retryAttempt = 0
12931300

1301+
PluviaApp.events.off<AndroidEvent.EndProcess, Unit>(onEndProcess)
12941302
PluviaApp.events.clearAllListenersOf<SteamEvent<Any>>()
12951303
}
12961304

0 commit comments

Comments
 (0)