Skip to content

Commit 54b36b1

Browse files
committed
Move setForeground call to onStartCommand
The setForeground() method is now called in onStartCommand instead of onCreate to ensure the service is promoted to foreground when started. Also updated service start to use startForegroundService for proper foreground service behavior.
1 parent 6a48b5b commit 54b36b1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/src/main/java/com/dergoogler/mmrl/wx/service/PlatformService.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class PlatformService : LifecycleService() {
2424
override fun onCreate() {
2525
super.onCreate()
2626
isActive = true
27-
setForeground()
2827
}
2928

3029
override fun onDestroy() {
@@ -40,6 +39,8 @@ class PlatformService : LifecycleService() {
4039
return START_NOT_STICKY
4140
}
4241

42+
setForeground()
43+
4344
lifecycleScope.launch {
4445
isActive = initPlatform(baseContext, intent.getPlatform() ?: return@launch)
4546
}
@@ -72,7 +73,7 @@ class PlatformService : LifecycleService() {
7273
mode: Platform,
7374
) {
7475
val intent = context.createPlatformIntent<PlatformService>(mode)
75-
context.startService(intent)
76+
context.startForegroundService(intent)
7677
}
7778

7879
fun stop(

0 commit comments

Comments
 (0)