We are developing a Delivery Partner App using React Native version 0.73.6. The core functionality of our app requires constant access and tracking of the user’s current location, even when the app is closed or running in the background.
To achieve this, we have integrated the react-native-background-actions
library, version 4.0.1, and followed all the steps outlined in the documentation for Android.
While the app does run in the background initially, we are facing issues with the app not staying in the background for an extended period across various Android devices. The duration for which the app remains active in the background is inconsistent and varies from device to device.
Here is a summary of our issue:
- The app needs to access and track the user’s current location continuously.
- We have used the
react-native-background-actions
library as per the documentation. - The app runs in the background but stops after an unpredictable amount of time on different Android devices.
Code Example:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package.name">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:directBootAware="true"
android:theme="@style/BootTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="exampleScheme" />
</intent-filter>
</activity>
<service
android:directBootAware="true"
android:exported="true"
android:foregroundServiceType="location|mediaPlayback"
android:enabled="true"
android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</service>
</application>
</manifest>
Steps to Reproduce:
- Integrate
react-native-background-actions
in a React Native app. - Follow the setup instructions for Android as per the documentation.
- Start the background service to track location.
- Observe the app’s behavior on different Android devices.
Expected Behavior:
The app should run in the background indefinitely, consistently tracking the user’s location across all Android devices.
Actual Behavior:
The app runs in the background initially but stops after an unpredictable duration, varying across different Android devices.
Additional Information:
- React Native version: 0.73.6
- Library version: 4.0.1
- Affected platforms: Android
- Devices tested: Various Android devices with different OS versions
We would greatly appreciate any guidance or solutions to ensure our app remains active in the background consistently across all devices. What other permissions or configurations do we need to keep the app running in the background all the time?
Thank you!
Link to the react-native-background-actions
documentation: react-native-background-actions
Please let me know if any further information is required.
While the app does run in the background initially, we are facing issues with the app not staying in the background for an extended period across various Android devices. The duration for which the app remains active in the background is inconsistent and varies from device to device.
Rajkumar Sendhav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.