如何创建Flutter后台服务,该后台服务在应用程序关闭时也可以使用

编程入门 行业动态 更新时间:2024-10-27 02:20:13
本文介绍了如何创建Flutter后台服务,该后台服务在应用程序关闭时也可以使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为大学的学术目的开发Flutter应用程序.现在,我需要运行某种始终在线"的后台服务才能使用蓝牙,最重要的是要从外部REST API获得定期更新.

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.

我已经从pub.dev(此和此),却找不到找到即用即用的完美解决方案(按预期...).我还看到了Kotlin的某些东西(此处).我想知道什么是实现我的目标的最佳选择(就最佳实践,完整性和简便性而言).

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.

在始终存在"的后台组件中处理API的最有效方法是实施推送通知服务. 使用这种技术,远程服务器可以启动与您的应用程序的通信,将其唤醒,然后执行需要执行的任务.

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.

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

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

更多推荐

如何创建Flutter后台服务,该后台服务在应用程序关闭时也可以使用

本文发布于:2023-11-27 05:02:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636710.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   可以使用   应用程序   Flutter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!