Android may kill running applications to increase battery life once the screen is turned off or they enter background mode. This is only desirable if the application is intended to only run in foreground (e.g. guidance applications), but will cause inconveniences in all other cases.

Therefore, from version 2.13.0+, we have implemented a Keep-Alive mechanism (activated by default) to prevent Android from killing or limiting the execution of applications using Situm SDK. This mechanism will cause the application to run always, even in the background or if the screen has been turned off. This comes with the following costs:

  • Users will see an always-on notification in the notification area.
  • Battery life will be significantly reduced.

For more information about battery life optimizations, please refer to Optimizing for Doze and App Standby and Background execution limits.

Should I deactivate the Keep-Alive mechanism?

It depends on your application:

  • Foreground-only applications: e.g. guidance apps. If your app requires computing the position only when the user is interacting with the screen, you can safely deactivate this mechanism.

  • Always-on applications (foreground and background): e.g. tracking and geomarketing apps. If your app is meant to keep computing locations even if it is running in the background or the screen has been turned off, you should not deactivate this mechanism.

How to deactivate the Keep-Alive mechanism?

You should only deactivate it if your application does not require to compute the position when the user is not interacting it. If you are unsure about this, we recommend not to deactivate the Keep-Alive mechanism.

In order to deactivate it, create a LocationRequest with useForegroundService(false).


LocationRequest locationRequest = new LocationRequest.Builder()
.useForegroundService(false)
.build();


For more info on the LocationRequest class, please refer to the Quick Start Guide - Start the positioning.

I can’t deactivate the Keep-Alive mechanism. Can I at least customize the persistent notification?

Yes. If you chose not to deactivate the mechanism, you can set a custom Notification, which serves a dual purpose:

  • Providing the users with information about why the application is being executed in background.
  • Managing interactions with the application from the notification drawer.

A custom notification can be added by creating a LocationRequest with foregroundServiceNotification(Notification).


LocationRequest locationRequest = new LocationRequest.Builder()
.useForegroundService(true)
.foregroundServiceNotification(notification)
.build();


For more information on these topics, please refer to PendingIntent and Building a notification.