Search code examples
servicedartflutter

How to create a service in Flutter to make an app to run always in background?


I would like to make my Flutter application to run always in background. With android, we have to create a Service that runs always in background. I don't find something about Services in the Flutter documentation.

Is it possible to do this kind of things with Flutter?


Solution

  • There isn't a way to do this directly from flutter right now although that may change at some point - see this bug/feature request. You do have a couple of options though.

    The first is to use MethodChannels and simply write the android code you want to create a background service (or if you want it to always be a background service you can probably do that without needing communication from the flutter side).

    The second is some combination of these two plugins - android_alarm_manager and android_intent. But that won't help for all use-cases.

    EDIT Feb 2021:

    Flutter now supports running background processes. See this page for details.