2

I'm software engineer using Flutter in Japan.
Developing an alarm app that wakes me up in the morning, and having trouble implementing the following.
I would appreciate it if you could help me.

Question.
I would like to know if there is a way to execute a specific process at a scheduled time, even if the app is killed or backGround.

Details.
I'm currently developing on an alarm app that sends local notifications & custom music at a specified time.
I was able to schedule local notifications to send at the specified time.
However, I can't find a way to run a specific process in the background at the same time.
(It's an image of a process that plays specific music selected by the user)

What I've found out
Confirmed that notifications can be sent on a specified day and at a specified time every week using flutter_local_notifications.
(execute flutterLocalNotificationsPlugin#zonedSchedule())

However, in flutter_local_notifications, there is no such thing as a listener to receive the notification itself.
(There is an onSelectNotification, but it doesn't work until user taps the notification bar.)

The library author says that there is no listener to fire such notification timing,
So I decided to use only local notifications in this library and look for another library to replace the background processing.
https://github.com/MaikuB/flutter_local_notifications/issues/1201

I found background_fetch and WorkManager to be particularly useful, but I gave up on using these libraries as well.
The reason is that with the above two libraries can only be executed in the sense of 15 minutes, as shown below, due to iOS limitations, and I suspect that the process cannot be executed at the intended timing.

workManagaer
https://pub.dev/packages/workmanager#customisation-android-only

// Periodic task registration
Workmanager().registerPeriodicTask(
    "2", 
    "simplePeriodicTask", 
    // When no frequency is provided the default 15 minutes is set.
    // Minimum frequency is 15 min. Android will automatically change your frequency to 15 min if you have configured a lower frequency.
    If you have configured a lower frequency. frequency: Duration(hours: 1),
)

background_fetch

Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period of background running-time. This plugin will execute your provided callbackFn whenever a background-fetch event occurs.

I think the only way to do this is to use MethodChannel to write and execute native code for each OS from Flutter.
I would like to know if there is a way to execute the scheduled process at the specified time even if the app is in kill or background state in Flutter, even if it uses MethodChannel.

Sorry Its so long. Please let me know.
Thank you very much

  • I don't understand what your reason is for not using those libraries. The 15 minute restriction I believe is imposed by the operating system itself. Why would you need more often than that? – Barry Feb 28 '22 at 22:04
  • Thanks for the reply. For example, let's say I want to create an alarm that wakes me up at 9am. If the process runs minimum 15 minutes, I think that I can not run an alarm process that will wake me up at exactly 9am.(ex: Last process time: 8:58 => next process time: 9:13) Is this understanding correct? – Ayumi Sashitani Mar 01 '22 at 14:05
  • @AyumiSashitani Have you find any solution to this, I'm also facing the same – Farazzz Feb 08 '23 at 10:18
  • @Farazzz No, I have not investigated it recently, but the situation remains the same. – Ayumi Sashitani Feb 18 '23 at 06:32

1 Answers1

0

The only doc provided for background process (alarm being one of the example cited) points out to an article on medium: https://docs.flutter.dev/development/packages-and-plugins/background-processes

Driky
  • 197
  • 12
  • Sorry for the late reply. And thank you very much for your reply. I have read through the medium you provided. I interpreted that as referring to the following sample. https://github.com/bkonyi/FlutterGeofencing I also checked the code inside, and I think not to be an example of scheduling like an alarm app. – Ayumi Sashitani Jan 09 '22 at 14:40
  • Also, the following section talks about scheduling, but only on Android. So it thought only mentions Android and not iOS scheduling implementaion. https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124#:~:text=Scheduling-,the,-geofencing%20service I apologize if this is an oversight or lack of research on my part, but if you have anything to add about the above I would appreciate your input. – Ayumi Sashitani Jan 09 '22 at 14:40