0

Foreground Service通过使用从主活动调用startForegroundService(Intent(applicationContext, ForegroundService::class.java)),当活动即将被销毁时,调用'stopService(Intent(applicationContext, ForegroundService::class.java))'。ForegroundService 中的 onDestroy 函数实现如下:

override fun onDestroy() {
    super.onDestroy()
    stopForeground(STOP_FOREGROUND_REMOVE)
    stopSelf()
}

尽管从 Main 活动中调用了 onDestroy 函数,但该进程似乎并未终止。(我在 Android Studio 的控制台上没有看到“进程 XXXXX 已终止。”的消息)。这不是终止前台服务或丢失一些额外函数调用的正确方法吗?

4

0 回答 0