react-native-background-actions icon indicating copy to clipboard operation
react-native-background-actions copied to clipboard

Task stops working after 3 minutes on android 14

Open Beckmann0o opened this issue 1 year ago • 20 comments
trafficstars

Hi guys, I'm trying to set up a task that can be done every 30 seconds, the idea is to run constantly. The problem is that in versions prior to Android 14 it works fine, but in Android 14 it works for 3 minutes and the application stops working. I think it may be because of the declared service type android:foregroundServiceType="shortService", maybe if I change the service type the task could run for longer, did anyone have the same problem?

Thank you very much!

Beckmann0o avatar Oct 18 '24 14:10 Beckmann0o

I am also facing the same issue, I have changed to foregroundServiceType, it's working for the first time but not everytime. Did you found any solutions @Beckmann0o ?

chowdhury-abhishek avatar Oct 20 '24 17:10 chowdhury-abhishek

same issue here 😕

carozo avatar Oct 21 '24 20:10 carozo

Hi guys, I'm trying to set up a task that can be done every 30 seconds, the idea is to run constantly. The problem is that in versions prior to Android 14 it works fine, but in Android 14 it works for 3 minutes and the application stops working. I think it may be because of the declared service type android:foregroundServiceType="shortService", maybe if I change the service type the task could run for longer, did anyone have the same problem?

Thank you very much!

Can you show your adb logs?

I think you can try change your fouregroundServiceType to syncData to take longer task

devtyty avatar Oct 22 '24 04:10 devtyty

También tengo el mismo problema. Cambié a closeupServiceType y funciona la primera vez, pero no siempre. ¿Encontraste alguna solución?@Beckmann0o?

Hello bro, I was able to make it run continuously by adding foreground type in the Android manifest, the problem is that when the screen is turned off for several hours the OS kills the service. Did you have any progress? I leave how to configure the manifest: <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="connectedDevice|dataSync|location">

Beckmann0o avatar Nov 06 '24 11:11 Beckmann0o

Hola chicos, estoy intentando configurar una tarea que se pueda realizar cada 30 segundos, la idea es que se ejecute constantemente. El problema es que en versiones anteriores a Android 14 funciona bien, pero en Android 14 funciona durante 3 minutos y la aplicación deja de funcionar. Creo que puede ser por el tipo de servicio declarado android:foregroundServiceType="shortService", tal vez si cambio el tipo de servicio la tarea podría ejecutarse por más tiempo, ¿alguien tuvo el mismo problema? ¡Muchas gracias!

¿Puedes mostrar tus registros adb?

Creo que puedes intentar cambiar tu fouregroundServiceType a syncData para que tarde más en realizar una tarea.

Hello, I already have it configured as follows: <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="connectedDevice|dataSync|location">

It works fine as long as the screen does not remain off for several hours, at which point the OS kills my service.

Beckmann0o avatar Nov 06 '24 11:11 Beckmann0o

También tengo el mismo problema. Cambié a closeServiceType y funciona la primera vez, pero no siempre. ¿Encontraste alguna solución?@Beckmann0o?

Hello, I changed the service type in the Android manifest and got it to work continuously but when the screen is off for several hours the OS kills the service, I am trying to solve that problem. I'll give you my current configuration in the manifest for the type of service.

<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="connectedDevice|dataSync|location">

Beckmann0o avatar Nov 06 '24 11:11 Beckmann0o

@Beckmann0o @devtyty @chowdhury-abhishek @carozo I tried the example from the library and app just crashes. but it works with older versions of android. But i am unable to get it working with android 14. Please help! I have a issue posted in https://github.com/Rapsssito/react-native-background-actions/issues/251

smitha-2020 avatar Dec 02 '24 15:12 smitha-2020

Hi @chowdhury-abhishek @carozo @Beckmann0o @devtyty

While the app is in the background, the microphone isn't working. However, it functions properly when the app is in the foreground, where both camera and microphone permissions are granted.

how can i solve this ?

I’m facing an issue where the microphone stops working when the app is in the background, even though the camera and microphone permissions are correctly granted when the app is in the background and it functions properly when the app is in foreground.

Can you please assist in resolving this? It would be greatly appreciated if someone could help or provide any guidance on how to fix this behavior.

Thanks in advance!

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <application> <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync"/> </application> </manifest>

vishalyad16 avatar Jan 27 '25 06:01 vishalyad16

Hi @chowdhury-abhishek @carozo @Beckmann0o @devtyty

While the app is in the background, the microphone isn't working. However, it functions properly when the app is in the foreground, where both camera and microphone permissions are granted.

how can i solve this ?

I’m facing an issue where the microphone stops working when the app is in the background, even though the camera and microphone permissions are correctly granted when the app is in the background and it functions properly when the app is in foreground.

Can you please assist in resolving this? It would be greatly appreciated if someone could help or provide any guidance on how to fix this behavior.

Thanks in advance!

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <application> <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync"/> </application> </manifest>

Do you have try set forgroundServiceType for "camera | microphone"?

Android Refs

devtyty avatar Feb 05 '25 04:02 devtyty

@devtyty Yes, I have tried the app, but it keeps crashing on samsung and moto devices

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>
    <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync|camera|microphone"/>      
</application>

vishalyad16 avatar Feb 05 '25 05:02 vishalyad16

@devtyty Yes, I have tried the app, but it keeps crashing on samsung and moto devices

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>
    <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync|camera|microphone"/>      
</application>

Can you show adb logs crash?

I think it maybe missing some permissions.

You must be make sure request permission audio before start foreground service.

Image

devtyty avatar Feb 06 '25 08:02 devtyty

@devtyty Yes, I have tried the app, but it keeps crashing on samsung and moto devices

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>
    <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync|camera|microphone"/>      
</application>

Can you show adb logs crash?

I think it maybe missing some permissions.

You must be make sure request permission audio before start foreground service.

Image

@devtyty Thanks for your response regarding this issue; the error I am getting is

Fatal Exception: java.lang.RuntimeException Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@da3a4d6 with Intent { cmp=com.explorastory/com.asterinet.react.bgactions.RNBackgroundActionsTask (has extras) mCallingUid=11071 }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{e17c8e7 24725:com.explorastory/u0a1071} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO] and the app must be in the eligible state/exemptions to access the foreground only permission

and the path where the code is added is node_modules\react-native-background-actions\android\src\main\AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> <application> <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="dataSync|microphone"/> </application> </manifest>

vishalyad16 avatar Feb 07 '25 11:02 vishalyad16

I use this but if i change anything other than shortservice my app get crashed when background service is starting.

I m using background service for continuos location tracking

princekasundra avatar Feb 12 '25 08:02 princekasundra

@princekasundra is there any alternative that we can use ?

vishalyad16 avatar Feb 12 '25 08:02 vishalyad16

I m still searching that, if any one finds please help.

princekasundra avatar Feb 12 '25 09:02 princekasundra

I m still searching that, if any one finds please help.

Sure

vishalyad16 avatar Feb 12 '25 09:02 vishalyad16

Any one faces same problem for location tracking using this lib???

princekasundra avatar Feb 12 '25 09:02 princekasundra

@princekasundra @vishalyad16 I am also facing the same issue , have you found any solution. I also have to do location tracking

DevDah1ya avatar Feb 17 '25 10:02 DevDah1ya

@devtyty I have fixed the crash issue, but there is still an issue with the microphone.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions"> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> <application> <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync"/> </application> </manifest>

vishalyad16 avatar Feb 18 '25 06:02 vishalyad16

FOREGROUND_SERVICE_LOCATION & DATA_SYNC: Required and correctly added for Android 14+ — ensures your foreground service is not silently blocked.

foregroundServiceType="location|dataSync": ✅ Correct — you're telling the system what types of foreground tasks this service will handle.

<service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="location|dataSync" android:exported="false" />

Means the service will stop when your app's task is removed (like swiping it away from recent apps).

This is okay if you're not trying to run location updates after the user kills the app manually.

❌ If your goal is to keep tracking even when the app is killed, this should be false and you need a strategy like WorkManager or BroadcastReceiver for BOOT and KILL handling.

Mansikansagara avatar May 24 '25 17:05 Mansikansagara