简体   繁体   中英

How to keep my flutter app running in the background when close?

I am building an app and I want it to show up in the user's notification bar and run in the background even when it's closed. Similar to "KWGT Kustom Widget Maker".

I've tried looking for libraries that allow this, but I can only find those related to java. Are there any available for Dart/Flutter or any other workaround? I am only targeting android devices.

After searching, I guess you have two solution:

You can use flutter wrapper for both android and IOS platform, but you won't be able to run jobs often than every 15 minutes. If you want to schedule jobs more often, you'll need to write platform dependent code, using the android_alarm_manager flutter package and background_fetch for IOS. You can trigger the correct one using the Platform function in dart.

您应该为此使用 Isolates,您也​​可以使用 android_alarm_manager 或 background_fetch 库

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.

For more information and a geofencing example that uses background execution of Dart code, see Executing Dart in the Background with Flutter Plugins and Geofencing , an article in the Flutter Publication on Medium. At the end of this article, you'll find links to example code, and relevant documentation for Dart, iOS, and Android

You can use the flutter_workmanager plugin.
It's better than the android_alarm_manager plugin since it uses newer API's on Android and also works with iOS.

我使用了一个名为flutter_background的包,它非常适合我。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM