【问题标题】:Oreo, foreground service stops when closed奥利奥,关闭时前台服务停止
【发布时间】:2017-12-20 10:58:18
【问题描述】:

我将服务用作前台服务。 在 android pre O 版本上一切正常。 但是在android Oreo中,当我关闭应用程序时,前台服务也关闭了......

我如何开始服务:

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"
            />

知道为什么它与应用程序一起关闭以及如何防止它吗?

谢谢!

【问题讨论】:

  • 我认为您必须要求用户检查您的应用程序服务的自动启动是否处于活动状态
  • 如何与整理前台服务相关???
  • 关闭应用是什么意思?您是否正在启动粘性服务?
  • 你能做一个简单的应用程序并上传它的源代码吗?无法重现前台服务的行为
  • @AndrewBrowiski 几天前注意到了这一点:这是我的 OnePlus 3T 操作系统版本中的某种错误(安装最后一个测试版)。因为我的朋友和我有相同的手机也解决了这个问题,他的设备没有问题。

标签: android service android-8.0-oreo foreground-service


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多