Android Question How to keep a service running all the time with targetSdkVersion="22" in Manifest?

JohnC

Expert
Licensed User
Longtime User
I need to keep an Android TV service running all the time and have some questions:

1) I am thinking of including "Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS" mode/setting as mentioned in https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546

The app will be running on devices running API 28+, but in order for a particular feature of the app to work correctly, I need to set the targetSDK=22.

So, will setting the foreground mode work on a device running API 28+ but with the manifest set to targetSDK=22?

2) Should I still do a PhoneWakeState.PartialLock even if the TV will stay powered on - is there any harm in including this line anyway?

3) Should/can I combine #StartCommandReturnValue: android.app.Service.START_STICKY with Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS

What would be the best practice to keep a service (foreground) running 24/7?

I am asking because when I use just the sticky option (using the default foreground setting), some users have reported the app gets killed.
 
Last edited:
Top