创建与 AlarmManager 一起使用的 AsyncTask
由于我只想连接到一个Web服务,以检查是否有更新,或者检查是否需要向该服务发送数据,我相信AsyncTask和AlarmManager非常适合此目的,但我不知道如何处理用户的 Internet 连接可用性。
基本上,我认为达到时间间隔后,我将不断检查互联网连接,如果可用,则连接到该网络服务,并在连接后下次重新启动 AlarmManager。我缺少的是不断检查互联网可用性,并为此正确使用 AlarmManager。任何建议对我来说都很好......
Since I just want to connect to a web service, in order to check whether there is an update or not, or to check whether there is a need to send data to that service, I believe AsyncTask and AlarmManager is perfect for this, but I don't know what to do about the Internet connection availability of the user.
Basicly, I think after reaching the time interval I'll constantly check for an internet connection, if available connect to that web service, and after the connections restart the AlarmManager for the next time. What I am missing is the constantly checking internet availability, and using AlarmManager properly for this. Any advice would be great for me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过创建一个带有无限循环的单独
线程
来检查互联网可用性。您可以在服务
中实现此线程...有关警报管理器,请参阅此文档:
http://developer.android.com/reference/android/app/AlarmManager.html
you can check for internet availability by creating a separate
thread with infinite loop
..you can implement this thread inservice
...for alarm manager refer this doc:
http://developer.android.com/reference/android/app/AlarmManager.html