Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to start foreground service using flutter_foreground_task package when called from callbackDispatcher. #583

Open
BigYajuu opened this issue Dec 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@BigYajuu
Copy link

Technology Version
Android SDK version 29
Workmanager version 0.5.2

Synopsis

I wanted to register a periodic task that could start foreground service (FGS) after a set delay, but it failed to run. The execution of the foreground service is done by yet another flutter package called flutter_foreground_task https://pub.dev/packages/flutter_foreground_task.

Details

The start of the FGS is triggered using FlutterForegroundTask.startService from the flutter_foreground_task package, and it is called from inside of the callback body of Workmanager().executeTask((task, inputData) async { ... }), which is called from the top-level callbackDispatcher() entry point. Therefore by design, when Workmanager().registerPeriodicTask( ... ); is called the FGS should begin autonomously, but it did not. My guess is that Android disallows FGS to launch from another isolate without proper passing of Android context. But since I am using a third-party FGS package there's really no wiggle room here.

I am beginning to lean towards to the concept of Android's ForegroundInfo though. And someone #573 has already raised a merge request regarding this feature, ready to be released. I am paying close attention to the progress of this.

Output of flutter doctor -v (partial)

[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [Version 10.0.22631.4602], locale en-US)
• Flutter version 3.22.1 on channel stable at C:\dev\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision a14f74ff3a (7 months ago), 2024-05-22 11:08:21 -0500
• Engine revision 55eae6864b
• Dart version 3.4.1
• DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:\Users\Chuyue Wu\AppData\Local\Android\sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
• All Android licenses accepted.

[√] Android Studio (version 2023.2)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)

[√] VS Code (version 1.94.2)
• VS Code at C:\Users\Chuyue Wu\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.102.0

@BigYajuu BigYajuu added the bug Something isn't working label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant