奥利奥后台服务

Oreo Background Services

在我们的应用程序中,我们使用多个服务和 Intent 服务进行 BLE 通信、麦克风录音等。

我们已经注意到新的背景限制和限制(是的,我们确实注意到它很晚,我知道)。我已经更改了使用 ContextCompat.startForegroundService() 函数和使用带有通知的 startForeground() 的实现,如文档中所述。

但是我们看到,当应用程序 killed 时,前台服务也会在几分钟后终止。它应该发生吗?如果应用程序在 background 中,前台服务是否应该仅继续工作?

此外,如果是这种情况,电池优化功能有什么作用?让服务仅在后台运行?当应用程序处于后台并启用此功能时,服务仍然可以被杀死吗?

我已经阅读了很多关于它的文档,但我仍然对应用程序 killed.

时的服务状态感到困惑

我们不介意为这些服务显示通知,但我们仍然希望它继续工作 "endlessly"。

But we saw that when the application is killed, the Foreground Service dies also after a few minutes. Should it happen? Should the Foreground Service will only continue to work if the app is in the background?

是的,它会破坏前台服务..,但它会在 micros 秒内重新创建...这是自然行为。即使您通过从最近的应用程序中滑动来杀死应用程序..!!

Pos只有你的前台服务代码..!!没有额外的代码,我会更正它,以便它可以按照我所说的方式运行..

Also, if this is the case what does the Battery Optimization feature do? Keeps the Service working while in background only? Can the Service still be killed while the app is the background with this feature on?

如果电池正在优化,那么它可能不会重新启动您的前台服务 ON_BOOT_COMPLETE

I've read a lot of docs regarding it but I'm still confused regarding the state of Service when the application is killed.

是的,我知道这完全是浪费时间,因为 google 文档在记录方面没有直接的方法,也没有供开发人员使用的示例代码...如果您想编写 4 个以上的代码android os 然后所有代码都需要根据版本代码进行编码..!!

We do not mind showing a notification for those services but we still want it to continue to work "endlessly".

它从来没有发生过......ENDLSSLY 必须用广播接收器来实现,当你想要你的服务似乎是 运行 无休止的..同样,你不能创建静态接收器,也不能调用它们像以前一样通过清单...您需要在运行时从前台服务创建它。

Where i can get example codes? No where... Google has no sample codes... just blah blah blah...

Short and sweet... I had lost my complete year and now well known about all above your questions and have implemented it in apps and apps are in market running quite good as expected... And i like to help them all as google lacks it in documentation.. Post your code , Let me know, and Get it worked from me


编辑:2

Google 基于 wrong conceptwrong implementationwrong supportwrong documentationwrong os ( Android ) wrong License 是开源的,允许 non - standard 公司修改和使用它。现在考虑它的缺点:

  1. 编写一个甚至支持多个版本的应用程序会让开发人员感到沮丧。说 LollipopMarshmallow。两种方式都不同,开发人员已经有 1000 个案例要处理,然后又是这个..
  2. 一次开发两个以上的版本时,情况变得最糟糕...完全是一团糟..
  3. 再次google在几个月的时间里不断改变规则...
  4. 由于没有适当的文档,开发人员只有一个选择,那就是拔头发..!!
  5. 这些还不够......,所以再次:-

体内:ColorOs 一加:OxygenOs 米:FunTouchOs . . . .

这是一个巨大的公司名单,他们不知道如何修改(以及为什么要修改...?)开始修改 stock-android..,其中 most 只允许 facebookGoogleWhatsappInstagram,主要社交应用程序供应商的服务仅在 Boot_complete.

进入内存

Why only these services and why not mine..?

因为买家不会购买 phone 以上软件无法运行的..!!没有人会接受这样的 phones..!!

Why not mine..?

这是一项业务

Is there any other way...?

不可能..!!当我们在 Googles Android Studio 上标准地开发应用程序,并在 google 的模拟器上测试它时,它拥有 stock-android 系统..!!所以不要保证它是否适用于每个制造商的设备..!!

Who is responsible for these all situations.. and what is solution..?

Google 应对所有这些挫败感负责,所有移动 phone 制造商已经采取了这种程度,现在 impos 可以处理.. Google 必须限制修改,还必须实施硬件支持系统..!!停止此类非托管操作系统的最佳方法。