1

According to Understanding App Standby an app can be put into standby if it appears as if the user doesn't use it on a regular base.

We have calendar & contact sync apps which are set up once and (ideally) run in the background without interacting with the user thereafter. These apps sync to the calendar and contacts databases, hence they have no UI which the user would have to open frequently. They only have an account management UI which you don't need very often.

So none of the conditions mentioned in the article above applies to our apps. In particular:

  • the user won't have to open it in order to "use it", so he barely launches it
  • the app doesn't run a foreground service
  • we don't show any notifications (unless an error occurs)
  • it's certainly not a device admin app

So my question is, what's the intended way for such an app (which is meant to run solely in the background) to avoid being put into standby by the system?

We have many reports form users saying the app stops syncing on recent Samsung devices unless it's being opened every 3 days. Adding the apps to the white list of unmonitored apps doesn't seem to help. Our logs show that after not launching the app for 3 days the sync adapters are not started anymore, not even when triggering a "manual" sync. Only when the app is opened manually it can continue to sync.

Do we really have to show a notification just to stay "alive"?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Marten
  • 3,802
  • 1
  • 17
  • 26
  • app standby is not the issue. Samsung has their own battery manager application called "smart manager" (at least on 6 and lower, not sure what the name is on 7+) that kills any app that has not been opened in 3 days, unless it is on the whitelist of said manager – Tim Nov 23 '17 at 10:12
  • Also see this post https://stackoverflow.com/questions/37205106/how-do-i-avoid-that-my-app-enters-optimization-on-samsung-devices and both answers – Tim Nov 23 '17 at 10:16
  • Unfortunately adding the app to the SmartManager white list didn't work for us. Still, after 3 days, all sync request are deferred and the sync adapter is not called any more. – Marten Nov 23 '17 at 10:53
  • how do you know? There are multiple whitelists, are you sure you put it on the smart manager's whitelist? – Tim Nov 23 '17 at 10:54
  • Yes, I'm pretty sure that I added it to the smart manager whitelist. Just to be sure I've started another test. I'll see the result in 3 days. – Marten Nov 24 '17 at 09:26

1 Answers1

0

From what I know, you can only achieve this by using a service:

https://developer.android.com/reference/android/app/Service.html

http://www.tutorialsface.com/2015/09/simple-android-foreground-service-example/

There is also a "persistent" flag in the Manifest, but I don't think it'll work for apps installed from the store.

android:persistent Whether or not the application should remain running at all times — "true" if it should, and "false" if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications.

jorjSB
  • 610
  • 4
  • 12
  • We've implemented the [SyncAdapter](https://developer.android.com/training/sync-adapters/creating-sync-adapter.html) pattern in which a special service of our app is periodically called by the system. The problem is, that doesn't work anymore after 3 days. I don't see how another service would help here. – Marten Nov 23 '17 at 10:55
  • It looks like your SyncAdapter approach might provide the functionality you're looking for, but may not guarantee its own longevity in the Android ecosystem. The specific Android Service (that jorjSB mentioned) however, is described as "A Service is an application component that can perform long-running operations in the background" [here](https://developer.android.com/guide/components/services). Maybe that's more useful? – ThePartyTurtle Jun 21 '18 at 17:42