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

Documentation Android Section not clearly describe impact ```foregroundServiceType=shortService```

Open BagasNS opened this issue 1 year ago • 7 comments

i struggling for over 1 day for finding this solution first i following installation step INSTALL.md everything is good, until my app is crashing after running background process for sometime (about 3-5 minutes)

here is the error Screenshot 2024-07-01 185152

then i found this documentation from official android page that describe about foregroundServiceType image

from that documentation i simply change my AndroidManifest.xml from this

  <manifest ... >
    ...
      <application ... >
        ...
        <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
        ...
      </application>
    ...
  </manifest>

into this

  <manifest ... >
    ...
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/> // adding this permission because im using foregroundServiceType="dataSync"
      <application ... >
        ...
        <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="dataSync"/> // changed to dataSync
        ...
      </application>
    ...
  </manifest>

after that my app is running in background without crashing, i didn't tested it for long time, so i don't know its working forever or not, but it not crashing for 3-5 minutes

so i suggest to update your documentation for android to listing possible value for foregroundServiceType and the impact for each value.

and at the end, thanks for working to build this lib, its awesome!

BagasNS avatar Jul 01 '24 12:07 BagasNS

@BagasNS, thanks for the feedback! Could you create a PR with this information so new users also benefit from your discovery?

Rapsssito avatar Jul 09 '24 09:07 Rapsssito

Sorry for the delay. I've been busy for the last month, but here we go.

BagasNS avatar Jul 29 '24 21:07 BagasNS

@BagasNS have checked on a lower Android device, such as Android 12. It crashes the same as before and only works properly on Android 14.

rajkumarthirumalai avatar Aug 05 '24 10:08 rajkumarthirumalai

I had a similar issue, that app was crashing after running for 3-5 minutes, 🤦🏾‍♂️ before stumbling upon this issue thread I also had to go through the android docs and changed foreground service type to location as my app is tracking user position in background, would have helped if I searched in issues first 🥲. Great work on the PR @BagasNS, @Rapsssito please merge, it will be really helpful for users.

My change:

  <manifest ... >
    ...
+   <!-- adding this as we use android:foregroundServiceType="location" -->
+   <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
    <application ... >
      ...
-     <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="shortService"/>
+     <!-- adding this as we fetch location in background -->
+     <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="location"/>
      ...
    </application>
    ...
  </manifest>

Also, I have checked in android 12 and android 14 working well for me in both environments without any issue. @rajkumarthirumalai can you elaborate on your issue?

SnehasisSahoo avatar Aug 20 '24 12:08 SnehasisSahoo

@BagasNS I've tried this solution, but it's still crashing

vishalyad16 avatar Sep 03 '24 07:09 vishalyad16

@BagasNS I've tried this solution, but it's still crashing

can you give some code to reproduce? you can create new git repository for minimal reproduce, i'll happy to check it out

BagasNS avatar Sep 03 '24 09:09 BagasNS

my app is crashing when im using foregroundServiceType="connectedDevice"

Faizan-Hurekatek avatar Sep 12 '24 07:09 Faizan-Hurekatek