Flutter: cross-platform way to keep application running in the background - flutter

I'm trying to figure out a way to keep a Flutter application running even if it's not in focus. For instance have a countdown running and play an alarm sound/show notification on completion, no matter what's running in foreground.
Can anyone point me in the right direction? Ideally something that works cross-platform.
I found this thread but it's almost 2 years old, so I'm thinking maybe there has been some development since then.

This looks like what you might want: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124. It's a nice article on Medium describing how to run things in the background on both iOS and Android, especially using the most recent releases of Flutter.
The official documentation for Flutter in the background is at https://flutter.io/docs/development/packages-and-plugins/background-processes. The key is to run your code in an Isolate, because you won't have access to the GUI Isolate when you are in the background.

Related

Is there a way to keep a timer going when phone is locked?

I'm trying to recreate the Stopwatch functionality of Android's default 'Clock' app, but cannot seem to find a way to keep the timer going when the screen locks.
It doesn't stop immediately but the time it continues for seems to vary and definitely does stop - I tested with both the Android 'Clock' app and mine running at the same time.
Any way around this? I was looking into Isolates, but after implementing it I don't think that is the solution here. I've been searching and I guess what I need is to be able to run Background Tasks?
Can we do this in dart+flutter? If not any suggestions? I assume you would be able to (or have to) do it natively in the android/ios codebase.
Similar problem I faced when I was building a music Player application. The audio_service package helped me with this background tasking. You might just go through this package code and implement as per your timer application and it will surely do fine.

iOS: how to run code in background when app is closed?

Using Swift5.2, iOS13.4,
I try to run code in the background (when app is fully closed) at a particular date.
Local Notifications work great if App is foreground (or if user-interaction then also in background).
Some people say (here or here, that you will have to use "background timer" or "Packet Tunnel VPN" tricks in order to keep your app alive in background and in order to have a chance to run some callback-method eventually.
But is there no easier way ?
My goal is to execute code at a particular date in the future (fully from background when app is closed). How would you do that with Swift5 and >iOS12 ?
Short answer, there is no easy way to do this. You can use Background Fetch to perform some actions if the app is running in the background (not fully closed). The easiest way I’ve found to perform actions when the app is fully closed is connecting to Google Firebase and using cloud functions (but those are written in JavaScript? I believe and it’s fairly complex).

It's possible run code like a "background service" when the app is closed using flutter?

I need to run a dart code for each 30s even if the application is closed. Is it possible?
Some workarounds suguested is use AlarmManager for Android, but, I not found solution for iOS.
There's no good article on how to implement an isolate to work when the app is closed without running some native code. In total, I have spent 2 full days trying to find a package for this, but nothing exists that works. Flutter_Isolate doesn't run when app is killed and Flutter Workmanager can only do print statements but can't take in any functions or any method call. Ultimately pathetic and very annoying. The only solution seems is to write native code to handle background tasks when app is closed. Shame on flutter.
Yes, it is possible. You can run Flutter in background.
In Flutter, you can execute Dart code in the background.
The mechanism for this feature involves setting up an isolate.
Isolates are Dart’s model for multithreading, though an isolate
differs from a conventional thread in that it doesn’t share memory
with the main program. You’ll set up your isolate for background
execution using callbacks and a callback dispatcher.
Source: Background processes
Yes its possible you can run a flutter app in background even if the app is closed using the following package:
https://pub.dev/packages/flutter_background_service
try using these two packages
https://pub.dev/packages/workmanager
https://pub.dev/packages/flutter_background_service

phonegap background service in iOS5

I am writing update checker program in xcode, my program needs background process( it needs to be run in background), so is it possible in phonegap, and is there any phonegap plugin for background services? Thanks
iOS does not allow background task to run more than a specific time limit.
Similar Post:
iPhone background task stops running at some point
Explanation:
http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html
The reasonable solution would be to implement a push notification and send a notification whenever there is an update on server.
It is definitely possible to run some JS code in the background to be checking this (https://github.com/jocull/phonegap-backgroundjs).
It won't be possible to do it for more than 10 minutes in the background, though (Run app for more than 10 minutes in background)
So you'll need both a combination of the first plugin I mentioned and the PN service that dhaval is suggesting.
Cheers!

iPhone how to: Develop app that alerts you on call time

Is there any way that I can develop an application that is running in the background that will detect when a call is being made, start a timer and then alert me at any set time, say before 5 minutes?.
I used to do a lot of iPhone programming but I haven't done any in 6 months. Is there any way to do this now?. Can anyone point me in the right direction?. Thank you.
Look at the documentation for callEventHandler in CoreTelephony. It's not exactly what you want, but read the discussion carefully. You'll be able to use this to do what you want in some cases. If your app is available for full blown background multitasking, then using it might even be reliable.