How to avoid app standby for background sync app?

618 Views Asked by At

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

1

There are 1 best solutions below

2
On

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.