Can I run code in the background while the app is terminated? - flutter

Is it possible to get code to run in the background (once the app has been terminated) in flutter? I have already tried the Workmanager library but that wasn't working properly.
Any suggestions are greatly appreciated.
Thanks

use android_alarm_manager to execute code in the background,
but make sure that you ask for permission (ignore battery optimization) to run in the background otherwise it won't run if the app is terminated permission_handler or for a simple android plugin permission_plugin

Related

Flutter Detect Notification Tray Pulldown

I'm trying to implement a feature based on the background/foreground status of a Flutter app.
Does anyone know of a way to detect if the notification/system try on a device is pulled down over the app?
Thanks.
Welcome to SOF
You can detect this using special permission in Android (https://developer.android.com/reference/android/Manifest.permission#EXPAND_STATUS_BAR).
But you need native code to run in Flutter.
There is a similar (almost) package out there, you may fork it:
https://pub.dev/packages/notification_shade

Flutter, Detecting that other apps are launched

I'm trying to develop an app that prevents a user from starting other application when my app is running. The scenario:
my app starts the timer
app detects launch of another app (could be anything other than my app)
if it detects, it cancels some achievements
Can anyone help? I saw some solutions on this topic, but could not find anything in Flutter.
Any ideas would help.
Thank you.
There is a few ways to do that but easy one to observe your app situation, you can use WidgetsBindingObserver to detect your app is background or not.
But if the case is not being background it is just depending to launch an app so there is a few ways which suggest in this answer you can try them.

Flutter : Run an app as a background service

I want to show a custom popup message whenever the user disconnects a cellular call. The problem is how to detect when the app is not running. any leads would be helpful.
It's been a while and there have been many developments.
First, there are some answers at How to create a service in Flutter to make an app to run always in background?
Also, flutter/Background processes will basically point you to medium/Executing Dart in the Background with Flutter Plugins and Geofencing (Sept 2018)
which is a Geofencing sample that involves a partnership between isolates, native Android/iOS code via MethodChannel, and PluginUtilities.getCallbackHandle (PluginUtilities)
Alas, there are many plugins available now:
https://pub.dev/packages/background_location
https://pub.dev/packages/android_alarm_manager (Android)
https://pub.dev/packages/background_fetch
https://pub.dev/packages/workmanager
https://pub.dev/packages/audio_service

How to make a task run in the background in Flutter

I have a music app that streams audio online. The only problem is it gets killed every time I exit the app which is not good for the user. They need it to keep running in the background even after exiting. How can I achieve this?
Can I run Dart code in the background of an Flutter app?
Yes, you can run Dart code in a background process on both iOS and Android. For more information, see the Medium article Executing Dart in the Background with Flutter Plugins and Geofencing.

How to run BlackBerry application in Background

I am working on a BlackBerry Application which requires the application be running once its sent to the background also.
I would really appreciate it if someone could guide me to any tutorials related to running background services in BlackBerry.
Background Application is a kind of process so you should extend Application instead of extending Uiapplication . In your main class implement all your code. You can also see this StackOverflow question for an example: Blackberry - Running Background Application
RIM has posted an article about running applications in background on their support forum:
Make a running UI application go to the background and resume in the foreground
You can use Alternate Entry Points to make your application run in the background. Check the link below for assistance
http://docs.blackberry.com/en/developers/deliverables/23567/Always_on_1380986_11.jsp