间隔发送意图
我想在用户指定的给定间隔内将意图传递给 IntentService。
我正在考虑使用 AlarmManager,但如果应用程序未运行,我不需要触发意图。根据我读到的内容,AlarmManager 将唤醒应用程序。
另一种选择是使用计时器运行方法。是否可以扩展 Application 类并拥有一个向 IntentService 发送意图的计时器,或者这是一个不合适的解决方案。
感谢您的建议:)
I would like to pass a intent to a IntentService in a given interval, specified by the user.
I'm considering to use the AlarmManager, but I don't need the intent to be fired if the app isn't running. And according to what I've read the AlarmManager will wake up the app.
Another option would be to run a method with a Timer. Is it possible to extend the Application class and have a timer that sends a intent to the IntentService, or is that an inappropriate solution.
Thankful for advice :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以扩展应用程序类,但如果您在每个活动中运行单独的计时器,并根据需要打开/关闭它们,设计将更加灵活。特别是如果您设想使用单独的线程。
另请查看 PendingIntents,它们提供了一种简单的机制来从服务中获取所需的数据。
You could extend the application class but the design will be more flexible if you run seperate timers in each of your activites, turning them on/off as required. Especially if you envisage ever using seperate threads.
Also take a look at PendingIntents they provide a simple mechanism to get the data you need back from the service.