Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.
MIT License
818 stars 117 forks source link

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

Open BagasNS opened 4 months ago

BagasNS commented 4 months ago

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!

Rapsssito commented 4 months ago

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

BagasNS commented 3 months ago

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

rajkumarthirumalai commented 3 months ago

@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.

SnehasisSahoo commented 3 months ago

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?

vishalyad16 commented 2 months ago

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

BagasNS commented 2 months ago

@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

Faizan-Hurekatek commented 2 months ago

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