plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

JobIntentService has been deprecated

Open madadam opened this issue 2 years ago • 7 comments

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

  • [X] I searched issues in this repository and couldn't find such bug/problem
  • [X] I Google'd a solution and I couldn't find it
  • [X] I searched on StackOverflow for a solution and I couldn't find it
  • [X] I read the README.md file of the plugin
  • [X] I'm using the latest version of the plugin
  • [X] All dependencies are up to date with flutter pub upgrade
  • [X] I did a flutter clean
  • [X] I tried running the example project

madadam avatar Feb 06 '24 16:02 madadam

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.

miquelbeltran avatar Feb 06 '24 19:02 miquelbeltran

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 avatar Feb 07 '24 08:02 madadam

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

madadam avatar Feb 07 '24 10:02 madadam

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?

miquelbeltran avatar Feb 08 '24 07:02 miquelbeltran

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).

madadam avatar Feb 08 '24 07:02 madadam

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.

miquelbeltran avatar Feb 08 '24 07:02 miquelbeltran

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[bot] avatar May 09 '24 00:05 github-actions[bot]