android - 可以保持前台服务处于活动状态以等待互联网连接吗?
问题描述
场景:我有一个在前台服务中运行的上传队列。当手机失去互联网连接时,我只需更改前台通知的消息。该服务会停止任何上传并只是等待重新连接互联网。服务中实现了一个广播接收器,用于侦听连接。当互联网再次连接时,服务只是继续上传。
此处的目标是确保在连接互联网后始终继续上传。
问题:为了等待互联网连接而让前台服务保持活动状态是否值得关注?广播接收器实际上没有收到互联网重新连接的消息是否存在巨大风险(从而导致前台服务永远保持活动状态)?
解决方案
As far i know it is worst scenario to keep foreground service alive
to wait for internet connection. Who knows this waiting time,
it may be hours, days... so who will wait till that time.
Save your data in local database which you have to upload.
Use Brodcaste reciever for the action of internet connectivity,
on connecting to internet use service for uploading the data.
推荐阅读
- javascript - 从其他 2 个对象创建一个新的对象数组
- wordpress - 按分类术语分类的 WordPress WP_Query 不显示所有帖子
- hashicorp-vault - 无法初始化保管库
- javascript - 在 react redux 中唯一地计算某些元素
- php - 无法在我的 formType 中加载 TranslatorInterface
- linux - 查找超过 7 天且在文件名的第三个字符中包含单词“t”的文件
- javascript - 现在将 localhost 上传到在线版本。它不起作用
- google-apps-script - 如何在脚本上安排触发器
- coldfusion - 使用 CFEXECUTE 执行批处理文件
- python - Python Curve_Fit 指数/幂/对数曲线 - 改善结果