Android - 前台服务和后台服务有什么区别?

Android - What is the difference between a foreground and background service?

来自android.com 它说前台服务是用户知道的东西,如果需要内存,前台服务不太可能被杀死。它说如果需要内存,后台服务可能会被终止。这是唯一的区别还是一项服务可以提供额外的功能?

我的主要问题是,如果有可能被杀死,为什么还要使用后台服务。任何人都可以提供应用程序使用后台服务的示例吗?

Is this the only difference or can one service offer extra features?

要使用前台服务,您必须在状态栏中显示 Notification。理想情况下,Notification 使用户能够控制应用程序的操作,例如停止前台服务正在做的任何事情(例如,播放音乐)。

why would a background service be used if it is likely to be killed

除其他原因外,如果您在没有充分理由的情况下将图标添加到他们的状态栏,用户会变得非常暴躁。

一般来说,您 两种服务类型都不使用,unless it is actively delivering value to the user。许多后台服务都是短暂的,只做一些特定的工作(例如,检查邮件服务器是否有新消息)然后就消失了。没有充分的理由为这项工作提供前台服务,尽管一些开发人员无论如何都会这样做。

Can anyone provide an example of an app would use a background service?

您设备上的大多数应用程序都使用后台服务。