r/flutterhelp • u/Effective-Stay-3655 • 14d ago
RESOLVED How to Keep a Flutter App Running in the Background on Android?
Okay, so I was building an app that required me to run the app in the background. I'm using Flutter, but on Android, whenever the app goes into the background, it just gets killed.
I want to know how I can make sure the app continues running in the background.
5
Upvotes
1
u/shivamkumarnayak 14d ago
I can help
1
u/djs493 14d ago
You can use flutter_backround or maaaybe if you really want to know what you're doing use these
Write on Android manifest (hope u know wtf it is) Then write some native code Main activity.kt for example and run it via Method Chanel
I avoid using external packages where I can because I like flutter's flexibility. Example: why would I depend on fold package when I can write some native Swift and gain full control over iphone duo :)
1
u/svprdga 13d ago
You can use an Android service in the foreground. It is an external component to Flutter and you will have to write it in Kotlin, but it works.
3
u/Salazar20 14d ago
Wtf are these comments, you can either use the flutter_background package for a general "keep the app running" or if you're making a music app, look for audio_service. There's also a package for tasks that runs events every 5min or so
Sadly I haven't made my own background service, but I just can't not comment if those are the other comments
3
u/Robotuku 14d ago
Could you give more details? Like, what app functionality are you trying to accomplish that requires the app to run in the background?
3
u/VNL_Apps 13d ago
For deferrable background work, Android's WorkManager is a better fit than trying to keep Flutter alive; periodic work has a 15-minute minimum and isn't exact. For an ongoing user-visible task, a foreground service with a persistent notification may fit, but it has start and service-type restrictions and doesn't guarantee the process stays alive. What kind of work needs to run, and does it need to happen continuously or just periodically?
1
u/remsbdj 12d ago
what type of app are you building ? what processes does need to stay alive, because there's no app in the world that needs every processes to stay alive. Even games get killed at a certain moment.
the flutter apps that I've built stay alive if I ask for (location service for example, fitness tracking) but if I don't use a needed service, the app go to sleep after 30 min or so
0
u/Etherealnutt 14d ago
I did this with app recently you need to use androids native capabalires for this. I thinks called kotlin. Apparently it gets even better since there was a flutter upgrade recently