android前台服务可以监听按键吗?
我正在尝试编写一个可以侦听音量键按下的服务,但我在某处读到服务不应该对用户操作做出反应。这也适用于前台服务吗?
谢谢!
I am trying to write a service that can listen for volume key presses but I have read somewhere that services are not supposed to react to user actions. Does that apply to foreground services as well??
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
前台服务是普通服务,唯一的区别是,当系统内存不足时,这些服务不太可能/不会被杀死,因为用户会主动意识到它们(例如,下载带有进度指示器的文件作为通知) )。如果你愿意的话,这只是一个更高优先级的内存。
所以是的,这也适用于那些。
Foreground services are normal services, the only difference is that those are less-likely/not killed when the system is low on memory, because the user is actively aware of them (e.g. downloading a file with a progress indicator as a notification). It's only a higher priority memory wise if you will.
So yes, that applies to those as well.