android.app.RemoteServiceException$ForegroundServiceDidNotStopInTimeException
On Android 15, foreground services of type dataSync must stop within a shorter timeout. We are observing a crash on devices running Android 15 with the following exception, even when using the latest flutter_local_notifications version (19.4.0).
Reference: Android 15 behavior changes for foreground services: https://developer.android.com/about/versions/15/behavior-changes-15#datasync-timeout
Crash Log:
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStopInTimeException
A foreground service of type dataSync did not stop within its timeout :
android.app.ActivityThread.generateForegroundServiceDidNotStopInTimeException (ActivityThread.java:2504)
android.app.ActivityThread.throwRemoteServiceException (ActivityThread.java:2466)
android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException
android.app.ActivityThread$H.handleMessage (ActivityThread.java:2820)
android.os.Handler.dispatchMessage (Handler.java:107)
android.os.Looper.loopOnce (Looper.java:257)
android.os.Looper.loop (Looper.java:342)
android.app.ActivityThread.main (ActivityThread.java:9638)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:619)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:929)
Android Manifest Configuration for Foreground Service:
<service
android:name="com.dexterous.flutterlocalnotifications.ForegroundService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:stopWithTask="false"/>
Flutter Doctor Output:
[√] Flutter (Channel stable, 3.32.4, on Microsoft Windows [Version 10.0.26100.4946], locale en-IN)
[√] Windows Version (11 Pro 64-bit, 24H2, 2009)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.97.2)
[√] Connected device (3 available)
[√] Network resources
flutter_local_notifications versions tested:
✅ 19.3.0 (crash observed)
✅ 19.4.0 (crash still occurs)
Expected Behavior: The foreground service should either complete or stop within the timeout window as per Android 15’s behavior change, or at least handle it gracefully without crashing.
Thanks for raising this. Would you be able to help solve the issue and raise a PR?