问题描述
我们目前正在开发一个健身追踪器应用程序Android应用程序.它在后台持续运行,并且在大多数设备上都可以正常运行,但是我们一直遇到一些问题,即该应用程序在某些三星设备上完全死机.经过调查,似乎某些三星设备具有完全自定义的应用优化"功能( http://forums.androidcentral.com/samsung-galaxy-s6/599408-app-optimisation-after-updating.html ),它基本上是(非常)原始的更高版本的Android中存在的Doze功能的基本版本,如果三天没有使用过,它们基本上只会杀死这些应用程序.
We are currently developing an Android app that is a fitness-tracker application. It runs constantly in the background, and it works fine on most devices, but we've been having issues with the application dying completely on some Samsung devices. After some investigation, it seems like some Samsung devices has a completely custom "App Optimisation" feature (http://forums.androidcentral.com/samsung-galaxy-s6/599408-app-optimisation-after-updating.html), which is basically a (very) primitive version of the Doze feature that exists in later versions of Android which basically just murders apps if they haven't been used for three days.
由于该应用程序或多或少只执行日志记录,并且无法打开活动,因此对我们来说是一个大问题,因为此功能已在许多三星设备上预先启用.通过使用前台服务可以解决该问题,但这是需要用不断通知打扰用户的解决方案的大锤,而且我们确实不需要将应用程序放在前台-正常运行就可以了Android的管理.
As this app is more or less only doing logging, and doesn't open the activity, it presents a big problem for us, because this feature is pre-enabled on many Samsung devices. The problem is solved by using a foreground service, but that is a sledgehammer of a solution that requires disturbing the user with a constant notification, and we really don't need the app to be in the foreground - we are fine with the normal power management of Android.
三星应用程序优化功能明确指出,如果三天未使用应用程序,它将优化"应用程序. 有人对三星认为的二手"有见识吗,我能以某种方式触发吗?
The Samsung App Optimisation feature clearly states that it will "optimise" apps if they have not been used for three days. Does anyone have insight in what Samsung considers to be "used" and can I somehow trigger that?
旁白:我认为,这是一个实施不当的功能,使Android上的开发更具敌意.除了我们的用例之外,所有Messenger应用程序都会中断.如果不是因为Facebook Messenger和Whatsapp被硬连线免除该应用程序的事实,那么用户会发疯,因为这会破坏他们的体验.
Side-rant: In my opinion, this is a badly implemented feature that makes development on Android more hostile. Besides our use case, it will any messenger applications break. If it were not for the fact that Facebook Messenger and Whatsapp are hard-wired to be exempt for the app, users would be going crazy because it would be breaking their experiences.
推荐答案
我已经拥有(并且目前拥有)三星设备,因此从用户的角度我对它的工作方式了解得很少.技术规范及其在内部的工作方式是一个完全独立的问题,我无法回答.
I've owned (and currently own) Samsung devices, so I know a little as to how it works from the user's point of view. The technical specifications and how it works on the inside is an entirely separate issue, and one I can't answer.
系统可以检测您是否打开了应用程序.三星将其用于应用程序优化,并将节省三天以上未使用过的应用程序的电量.但是,这是一个糟糕的系统.
The system can detect if you open an app. Samsung uses that in their app optimization, and will save power on apps that haven't been used in over three days. It is a terrible system though.
它会忽略可能对应用程序至关重要的后台进程,即使它是您积极使用的应用程序(例如健身追踪器),也会出现问题.引用应用优化列表中的内容:
It ignores background-processes that may be critical to apps, and even if it is an app you actively use, like a fitness tracker, it will have issues. To quote what it says inside the app optimization-list:
(挪威语的粗略翻译,最初取自运行Android 6的S6)
(Rough translation from Norwegian, originally taken from an S6 running Android 6)
因此,手动或自动设置的应用(3天不使用)可能会导致后台进程出现各种问题.但是请记住,用户可以将任何应用设置为永远不节省电池,并且忽略自动设置.因此,考虑到这一点,让我们考虑可能的解决方案.
Therefore, apps that have been manually, or automatically set (3 days of no use) may give various issues with background processes. But remember that the user can set any app to never save battery, and ignoring the automatic setting. So with this in mind, let's consider possible solutions.
在一种情况下,您无需担心应用程序和应用程序优化:当应用程序优化被完全禁用时.
There is one scenario where you do not need to worry about the app and app optimization: When app optimization is disabled entirely.
除此之外,您实际上只能做两件事:
Looking aside that, there is really only two things you can do:
-
在Samsung上向用户询问要为您的应用禁用电池优化功能,以防止出现问题
Ask users on Samsung to disable battery optimization for your app to prevent issues
如@MinaSamy所建议(在其现已删除的答案中),SyncAdapter并具有定期同步.请注意,我尚未对此进行测试,所以我不知道它是否有效.
As @MinaSamy suggested (in their now deleted answer), SyncAdapter and having a periodic synchronization. Note that I haven't tested this, so I don't know whether it works or not.
还有第三个选项,这实际上不是解决方案,但是您可以忽略它,并在禁用应用程序优化时赌博,或者根本不关心它.
And there's also a third option, which really isn't a solution, but you can ignore it and gamble on app optimization being disabled, or just not care about it at all.
据我所知,除非三星增加了一些防止意外开放的保障措施或增加了某种最低活动要求,否则开放就足够了.它似乎是一个愚蠢"功能,它以硬编码规则运行,而不是动态系统,该系统实际上会检测应用程序的使用并相对于此设置节能.它易于启用",但幸运的是也易于禁用.
As far as I know, unless Samsung added some safeguards against accidental opening or added some kind of minimum activity requirement, opening is enough. It appears to be a "stupid" feature, which runs on hard-coded rules rather than a dynamic system that actually detects app use and sets power saving relative to that. It's "easy to enable", but fortunately easy to disable as well.
这意味着您无法触发将其保持活动状态的事件(除非SyncAdapter可以做到这一点)
Meaning you cannot trigger an event that will keep it alive (unless SyncAdapter does the trick)
要弄清事实,请从 @Neil的答案:
有点.总共有四个设置,其中三个是特定于应用程序的,它存储在数据库中(或其他某种形式的数据存储).可以使用这四个设置(尽管非常浅)来更改应用程序优化的行为:
There kinda is. There are a total of four settings, three of which are app-specific, and it is stored in a database (or some other form of data storage). These four settings can be used, although extremely shallow, to alter the behavior of the app optimization:
- 始终优化
- 自动优化
- 永远不要优化
- 禁用应用优化
前三个选项基于每个应用程序,这意味着每个应用程序可以有单独的设置.禁用应用程序优化正是您所期望的:它会禁用所有应用程序的全部功能.如果将其完全禁用,则没有任何优化.
The first three options are on a per-app basis, which means each app can have separate settings. Disabling app optimization is exactly what you'd expect: it disables the entire feature for all apps. If it's disabled entirely, nothing is optimized.
这篇关于三星的“应用优化"该功能会在3天后杀死后台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!