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

JobIntentService has been deprecated #2571

Open
8 tasks done
madadam opened this issue Feb 6, 2024 · 7 comments
Open
8 tasks done

JobIntentService has been deprecated #2571

madadam opened this issue Feb 6, 2024 · 7 comments

Comments

@madadam
Copy link

madadam commented Feb 6, 2024

Platform

Android

Plugin

android_alarm_manager_plus

Version

3.0.4

Flutter SDK

3.16.8

Steps to reproduce

JobIntentService has been deprecated. The android reference suggest to use WorkManager instead.

However, perhaps running background jobs shouldn't even be the concern of this plugin? Maybe it should just run the callback directly inside the broadcast receiver and if people need to run long running task they can spawn them themselves using the workmanager plugin or similar?

Code Sample

No response

Logs

/home/adam/.pub-cache/hosted/pub.dev/android_alarm_manager_plus-3.0.4/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmService.java:17: warning: [deprecation] JobIntentService in androidx.core.app has been deprecated
import androidx.core.app.JobIntentService;

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.8, on Ubuntu 22.04.3 LTS 5.15.0-92-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (1 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Checklist before submitting a bug

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@madadam madadam added bug Something isn't working triage labels Feb 6, 2024
@miquelbeltran
Copy link
Member

I'd suggest updating the README with this information. So telling users that this plugin is deprecated, and they should use workmanager instead. We can keep the plugin around and up-to-date for legacy purposes, until the day Android drops the API officially.

@madadam
Copy link
Author

madadam commented Feb 7, 2024

telling users that this plugin is deprecated, and they should use workmanager instead

No, you misunderstand. This plugin is not deprecated. Only the JobIntentService class (from the android SDK) is. This plugin uses that class to execute jobs on the background. This is because you are not supposed to run long running jobs directly on BroadcastReceiver (they are limited to max 10 seconds or so). So this plugin schedules them with JobIntentService to run in the background instead.

The android docs suggest to use WorkManager instead so one way to resolve this issue would be to just replace JonIntentService with WorkManager.

Another option I think would be to not use any background runner at all, just run the job directly inside the broadcast receiver and update the README to instruct the uses that if they want to run long running job they should schedule it on the background themselves. One convenient way to do that is to use the workmanager flutter plugin.

Also, the workmanager plugin is not a replacement for android_alarm_manager_plus. The reason is that workmanager can run the jobs only while the app itself is running (in the foreground or in the background) but android_alarm_manager_plus can run them even when it's not which is useful in some cases.

@madadam
Copy link
Author

madadam commented Feb 7, 2024

Btw, I'd be happy to create a PR, just wanted to agree on the approach first.

@miquelbeltran
Copy link
Member

My understanding is that the JobIntentService is handling the received alarms in a queue, launching a startBackgroundIsolate and managing the Flutter background executor to process them.

I am not sure if just using a broadcast receiver can do that. I think you still need some sort of background service managing the Flutter isolate, or can that be done directly in the broadcast receiver?

@madadam
Copy link
Author

madadam commented Feb 8, 2024

Hm, I guess the broadcast receiver would have to initialize the flutter executor for each received intent (because I don't think it's state is preserved between invocations) which is not ideal. In that case I'd just go with replacing JobIntentService with WorkManager (the android class, not the flutter plugin).

@miquelbeltran
Copy link
Member

In that case I'd just go with replacing JobIntentService with WorkManager (the android class, not the flutter plugin).

Yep, I was thinking the same. Still Alarms are scheduled like before, but the isolate is managed by a workmanager service.

Copy link

github-actions bot commented May 9, 2024

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants