Skip to content

Commit eea409e

Browse files
meliksahcakirrDev-hwang
authored andcommitted
fix: DidNotStartInTimeException & DidNotStopInTimeException
1 parent d628c36 commit eea409e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundServiceManager.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ class ForegroundServiceManager {
6060
ForegroundTaskOptions.updateData(context, argsMap)
6161
ForegroundTaskData.updateData(context, argsMap)
6262
NotificationContent.updateData(context, argsMap)
63-
ContextCompat.startForegroundService(context, nIntent)
63+
// Use startService instead of startForegroundService because the service
64+
// is already running in the foreground and we only need to deliver the
65+
// update command. This avoids the startForeground() contract requirement.
66+
context.startService(nIntent)
6467
}
6568

6669
/** Stop the foreground service. */
@@ -76,7 +79,10 @@ class ForegroundServiceManager {
7679
ForegroundTaskOptions.clearData(context)
7780
ForegroundTaskData.clearData(context)
7881
NotificationContent.clearData(context)
79-
ContextCompat.startForegroundService(context, nIntent)
82+
// Use startService instead of startForegroundService because the service
83+
// is already running in the foreground and we only need to deliver the
84+
// stop command. This avoids the startForeground() contract requirement.
85+
context.startService(nIntent)
8086
}
8187

8288
/** Send data to TaskHandler. */

0 commit comments

Comments
 (0)