Android Service & Foreground Service
Android 8.0 开始,Service 必须使用 startForegroundService 指定为前台服务,并在 AndroidManifest.xml 文件中进行权限声明,Service 可以在后台运行,而 Foreground Service 则是前台服务,会显示一个通知栏。Service 的常用方法有 onCreate()、onStartCommand() 和 onDestroy(),需要在 AndroidManifest.xml 文件中进行注册才能生效。
原文中文,约3000字,阅读约需8分钟。