如何创建在应用程序关闭时也能工作的 Flutter 后台服务 [英] How to create a Flutter background service that works also when app closed

查看:26
本文介绍了如何创建在应用程序关闭时也能工作的 Flutter 后台服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为大学的学术目的开发 Flutter 应用.现在,我需要运行一种永远在线"的后台服务,以便使用蓝牙,最重要的是从外部 REST API 获取定期更新.

我已经从 pub.dev (

解决方案

对于这种事情,你必须依赖原生机制.

在始终存在"的后台组件中处理 API 的最有效方法是实现推送通知服务.使用这种技术,远程服务器能够开始与您的应用通信,唤醒它,然后执行任何需要执行的任务.

此外,在 Android 中,您有前台服务即使应用程序关闭,它也会运行.

I am developing a Flutter app for academic purposes in university. Now, I need to run a sort of "always on" background service in order to use Bluetooth and most importantly to get periodic updates from external REST APIs.

I've already checked those two libraries from pub.dev (this and this) without finding the perfect solution that works out-of-the-box (as expected...). I also saw something native with Kotlin (here). What I would to know is what is the best option in order to achieve my goals (in terms of best practices, completeness and with simplicity in mind).

Have a look at the following image for a more schematic view:

解决方案

For this kind of things you have to rely on native mechanisms.

The most efficient way to deal with APIs in an "always existent" background component is to implement a push notification service. Using that kind of tech a remote server is capable of starting communication with your app, awaken it and then perform whatever task needs to be performed.

Also, in Android, you have foreground services which will run even if the app is closed.

这篇关于如何创建在应用程序关闭时也能工作的 Flutter 后台服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆