我正在为大学的学术目的开发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后台服务,该后台服务在应用程序关闭时也可以使用
发布评论