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

feat: Long-running workers on Android devices #573

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wagner1343
Copy link

@wagner1343 wagner1343 commented Oct 21, 2024

This pull request introduces foreground service support on Android devices as per Android workmanager docs Support for long-running workers.

Foreground service support:

  • Added new methods createForegroundInfo and createNotificationChannel in BackgroundWorker.kt to handle the creation of foreground notifications and channels.
  • Introduced SetForeground data class and parseSetForegroundCall method in Extractor.kt to parse method calls related to setting foreground options. [1] [2]
  • Added setForeground method and SetForegroundOptions class in workmanager.dart to set foreground options from Dart code. [1] [2]

Code refactoring and improvements:

  • Refactored onMethodCall method in BackgroundWorker.kt to handle the new SET_FOREGROUND method call.
  • Updated imports and removed redundant imports in BackgroundWorker.kt and Extractor.kt. [1] [2]

These changes allows tasks to run as foreground services.

This PR addresses issue #236, but goes against the recomendation on #511 of using Workmanager.registerProcessingTask to implement long-running wokers on android.
Since the implementation of long-running workers on Android tightly depends on specific requirements such as handling notifications and activating a foreground service on the run, a decision was made to create a dedicated API which laverages ListenableWorker.serForegroundAsync and minimally handles notification management in order to implement long-running workers while following android guidelines.

Copy link

docs-page bot commented Oct 21, 2024

To view this pull requests documentation preview, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~573

Documentation is deployed and generated using docs.page.

@wagner1343 wagner1343 changed the title Long-running workers on Android devices feat: Long-running workers on Android devices Oct 21, 2024
@wagner1343 wagner1343 marked this pull request as ready for review October 21, 2024 14:25
@wagner1343
Copy link
Author

@ened I Kindly ask for your input on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant