首页 文章

奥利奥,前台服务在关闭时停止

提问于
浏览
0

我使用服务作为前台服务 . 在Android前O版本一切正常 . 但是当我关闭应用程序的Android奥利奥时,前台服务也关闭了...

我在这里如何开始服务:

val i = Intent(activity, MyService::class.java)
ContextCompat.startForegroundService(activity, i)

而不是内部服务 onStart

val builder = NotificationCompat.Builder(context, MY_CHANEL_ID)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(title)
                .setContentText(message)
                .setContentIntent(resultPendingIntent)

        val notification = builder.build()

        startForeground(notificationId, notification)

清单中的服务:

<service
            android:name=".data.service.MyService"
            android:exported="true"
            android:enabled="true"
            />

任何想法为什么它与应用程序关闭,如何防止它?

谢谢!

1 回答

相关问题