-
Notifications
You must be signed in to change notification settings - Fork 237
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
Ability to stop foreground service when app is closed from recents #342
Comments
Foreground service are meant to live beyond the activity's lifecycle and used only for long running task that outlive the UI, which means it's meant to survive even after the app is cleared from recent. I'm not sure if foreground service is the correct use case for your scenario. Seems like it would be better to just show progress on the component itself since it's killed after app is no longer active in foreground.
Do you have a reproducible example for this? I just checked the code and It's running a headless Task so you should be able to execute your task even if the app is no longer in active state. With that being said, a quick hack would be to add <application>
<service android:name="app.notifee.core.ForegroundService"
android:stopWithTask="true" />
</application> |
My app is streaming sound and I have to keep it running in case an audio stream changes. So I'm not sure if there's a better way to do this than run in Foreground Service. When starting the foreground service my whole app is running (all network requests etc). But when I close the app from recents, UI is unmounted but seems like rest of the code is still running. This causes trouble - for example setting React state will fail. I would like to simply avoid this behaviour. I don't need the app running when the user wants to stop it manually. Right now it seems that that adding |
Assuming your notifications have
|
Yes I'm doing that already (and the notification is gone). But the Headless seems to be going. One example: |
PR that potentially could be introduced voximplant/react-native-foreground-service#32 |
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. |
Hi, did you find any solution for this? |
Im having the same issue, the process never completely ends |
Foreground service and app process are two different things. Android OS handle the lifecycle of your app for you, so naturally the best practices is to let the OS handle it. I don't think it's the responsibility of a notification library to expose a function for you to kill the app since that's an entirely different thing. |
I'm encountering an opposite issue where, after specifying |
The behavior described - with the foreground service still running and keeping the app process alive after the app has been dismissed - is the behavior of foreground services in Android. But when you say the React Native context is gone - this is confusing. Foreground services use the same process as the application process. Infact you can access application state from within your foreground service, this is even true after the application has been swiped away in recents - the process has not been killed if a foreground service is still running. From the docs: A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of. If you want to manually alter this behavior and kill the process when the user swipes away from recents there's an answer here describing how - https://stackoverflow.com/questions/19568315/how-to-handle-running-service-when-app-is-killed-by-swiping-in-android/26882533#26882533 I can't speak to what some react native library is doing... |
setting android:stopWithTask="true" is not working. Please suggest any other solution. |
I am facing the same issue here. |
I've been trying to use foreground services and managed to run things in the background. The problem is that's not always that easy to stop the service. When the app is "swiped out" from recents the service is still running, but the React Native context seems to be gone which is causing trouble.
Android potentially offers stopping the service. Seems like adding
onTaskRemoved
and stopping the service there might help. Someone posted this. How this could be integrated into the service in Notifee? I'm happy to contribute but I'm not sure how to make it configurable from JS side.The text was updated successfully, but these errors were encountered: