1

In Android 13, Foreground Service is stopped when the application is background and battery is restricted. This happens after a minute or so.

As per the Android developer guide the current running services will be stopped and new services will be not launched and below is the link for the same. Please let me know how to keep service running even if the battery is restricted and application is background?

https://developer.android.com/topic/performance/background-optimization

I have modified code as below, but still the foreground service is stopped and removed the notification from the tray.

val notification: Notification = ...;
Service.startForeground(notification, FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE)

<manifest>
    ...
     <service
        android:name=".services.TestService"
        android:directBootAware="true"
        android:enabled="true"
        android:exported="false"
        android:foregroundServiceType="connectedDevice"
        android:stopWithTask="false" />
</manifest>

Starting ForeGroundService

val startIntent = Intent(applicationContext, TestService::class.java)
startIntent.action = ACTION_START_FOREGROUND
ContextCompat.startForegroundService(applicationContext, startIntent)
NikhilReddy
  • 6,904
  • 11
  • 38
  • 58

0 Answers0