首页 > 解决方案 > 可以保持前台服务处于活动状态以等待互联网连接吗?

问题描述

场景:我有一个在前台服务中运行的上传队列。当手机失去互联网连接时,我只需更改前台通知的消息。该服务会停止任何上传并只是等待重新连接互联网。服务中实现了一个广播接收器,用于侦听连接。当互联网再次连接时,服务只是继续上传。

此处的目标是确保在连接互联网后始终继续上传。

问题:为了等待互联网连接而让前台服务保持活动状态是否值得关注?广播接收器实际上没有收到互联网重新连接的消息是否存在巨大风险(从而导致前台服务永远保持活动状态)?

标签: 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.

推荐阅读