-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreground service freezes when app dismissed #1078
Comments
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
|
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
I am facing the same issue. |
I can reopen this but there is a very constrained amount of dev time I have - if anyone that is affected by this can dig in to troubleshoot it, that's the way to move this forward. Note that this may be affected by new architecture being enabled or not - if you are on react-native 0.76+ with bridgeless enabled this package is mostly working but there are reports that the new architecture mode causes foreground-service freezing. That may be the same issue as originally logged here it may not, I am unsure. But testing with new architecture enabled vs disabled is a good first step at diagnosis. Beyond that, unsure. |
Hey @mikehardy, I don't have access to Android 14 but a lot of users has reported this issue. My app has a timer feature that users a foreground service to resume/pause the timer. The feature works fine initially but after around 5 minutes closing the app, it freezes. Nothing works. I am not able to recreate it on Emulator. Do you know how it can be recreated? Also, is there a workaround to fix the freeze temporarily? |
I wasn't even aware this is a problem as I don't use the module like this in any way - so I don't reproduce it either and I'm unaware of any workarounds. The only thing I know is that it may be related to new architecture. But it may not. Someone who is impacted and motivated to troubleshoot will have to start instrumenting the code and finding reproduction scenarios and determine a root cause. Getting access to an Android 14 phone should be possible on the used market perhaps if a real device (not emulator) is required to reproduce. Perhaps someone else impacted is able to reproduce this on the emulator, that would be useful to know if so. |
Thanks @mikehardy for your time and suggestions :) |
Android 14: Foreground Service works on Foreground but not on Background I'm experiencing an issue where the foreground service works as expected while the app is in the foreground but stops working when the app is in the background on Android 14. This setup works perfectly on Android 13, where the service continues to run in both foreground and background. Here are my details:
Code ImplementationForeground Service Start Code: const startForegroundService = async () => {
if (Platform.OS === 'android' && Platform.Version >= 26) {
// Step 1: Create a notification channel
await notifee.createChannel({
id: 'locationChannel',
name: 'Location Tracking Channel',
importance: AndroidImportance.LOW, // Adjust as necessary
});
}
// Step 2: Register a minimal foreground service
notifee.registerForegroundService(async () => {
// Minimal function with no interval or tasks to reduce strain on the main thread
return new Promise(() => {
console.log("Foreground service registered.");
});
});
// Step 3: Display the notification as a foreground service
await notifee.displayNotification({
title: 'Tracking location updates',
body: 'Tracking location of user',
android: {
channelId: 'locationChannel',
asForegroundService: true,
smallIcon: 'ic_launcher', // Ensure this icon exists in res/drawable
},
});
};
**Foreground Service Stop Code:**
```javascript
const stopForegroundService = async () => {
try {
await notifee.stopForegroundService();
console.log("Foreground service stopped.");
} catch (error) {
console.error('Failed to stop foreground service:', error);
}
};
### Expected Behavior
- The foreground service should continue running in the background and display location tracking updates as a notification.
### Actual Behavior
- The foreground service stops when the app goes into the background on Android 14.
### AndroidManifest.xml Configuration
Here is my `AndroidManifest.xml` setup, including permissions and service configurations:
```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_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"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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"
android:supportsRtl="true">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDxn5xb9-opF0sOL8SUl33yOplQ6qZebvk"/>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Notifee Foreground Service -->
<service
android:name="app.notifee.core.ForegroundService"
android:foregroundServiceType="location"
tools:replace="android:foregroundServiceType" />
</application>
</manifest> |
@muhammadasifdotai thank you for the details! May I ask a couple followon questions?
|
1. ArchitectureI'm using the old architecture (Paper). 2. Testing Results
|
Hmm - I wonder if any of the suggestions from https://dontkillmyapp.com/ would help with your android 14 case |
Also, even if the only device reproducing it is your physical android 14 device I strongly encourage you to plug in to your development computer during reproduction and |
Have tried about just about every config concievable to get the foreground service running but it just won't continue executing as soon as I dismiss the parent app to the background.
The text was updated successfully, but these errors were encountered: