您是否需要实现 AIDL 才能使服务在应用程序生命周期之外运行?
我有一项服务可以发送带有定时任务的通知。我需要此服务在应用程序的生命周期之外运行,但我只需要在应用程序的生命周期内访问服务功能。本地服务就足够了还是我需要实施 AIDL? 谢谢。
I have a service that will send out notifications with timed tasks. I need this service to run outside the life of the application, but I only need to access the services functions during the lifespan of the app. Is a local service enough or do I need to implement AIDL?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望您指的是
AlarmManager
和IntentService
,这样您的服务仅在内存中保留尽可能短的时间,足以完成一些工作,提高通知
,然后走开。不要编写试图永远存在的服务,因为这是不可能的——用户或操作系统会杀死你的服务。通过提出这个问题,我相信您有更根本的问题,例如没有使用
AlarmManager
和IntentService
进行定期工作。您的 raise-a-Notification
-periodically 服务不应运行,因此不应存在您尝试访问的“服务功能”。By this, I hope you mean
AlarmManager
and anIntentService
, such that your service is only in memory for the minimum possible time, enough to do a bit of work, raise theNotification
, and go away. Do not write services that attempt to live forever, since that is impossible -- users or the operating system will kill off your service.By asking that question, I believe that you have more fundamental problems, such as not using
AlarmManager
and anIntentService
for your periodic work. Your raise-a-Notification
-periodically service should not be running, and hence there should be no "services functions" that you are trying to access on it.你不“实现 AIDL” - AIDL(android 接口定义语言)是一种推荐但非强制的便利/抽象机制,用于生成实现 Binder RPC 接口所需的代码,这是与服务通信的推荐但不是唯一的方式。
You do not "implement AIDL" - AIDL (android interface definition LANGUAGE) is a recommended but not mandatory convenience/abstration mechanism for generating the code needed to implement a Binder RPC interface, which is the recommended but not only way of communicating with a service.