IntentService 和 AlarmManager
我找不到从 AlarmManager 启动 IntentService 的方法。对于普通服务来说很简单(将其添加到清单中,然后将其包装在 Intent 中),但我无法使其与 IntentService 一起使用 - 应用程序不断崩溃并显示“java.lang.RuntimeException:无法实例化服务”。 IntentService本身没有任何问题(1行代码)。有什么帮助吗?
Possible Duplicate:
Android RuntimeException: Unable to instantiate the service
I can't find a way to start IntentService from AlarmManager. It is simple for normal service (add it to the manifest, then wrap it up in Intent), but I can't make it work with IntentService - app keeps crashing with "java.lang.RuntimeException: Unable to instantiate service". There is nothing wrong with the IntentService itself (1 line of code). Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 AlarmManager 触发 IntentService 应该没有问题,而且我不止一次这样做了。在 IntentService 的例子中,我遇到过几行代码就足以解决问题的情况。
确保您的 IntentService 具有这样的构造函数:
因为警报管理器将尝试在不带参数的情况下实例化它,而原始的 IntentService 构造函数 接收 String 作为参数。
There should be no problem to fire IntentService from AlarmManager, and I did it more than once. In the case of IntentService I met cases where a few lines of code were enough to make the problem.
Make sure your IntentService has a constructor like that:
Because alarm manager will try to instantiate it with no parameters, and the original IntentService constructor receives String as a parameter.