• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Endless Background Service

Hello everyone, I 'm working on a project and I'm supposed to make an app where it has a background service which lasts even the app is closed/killed ! , I've made everything and when I stop the service itself it starts again, but my problem is when I kill the app the service also dies [this's what I want you to help me with] !!

I've tried a looooot of solutions but nothing works
sad.png
sad.png
here's a sample project that I've tried, but it failed.

https://github.com/Jamal-Alkelani/FEService

Pleaseeeeeeeee anyone can help
sad.png


-->All I need if the user close/kill the app I don't want the SERVICE to be killed !!!

Thanks in Advance ♥ ♥
 
thank you for replying ...
Yess sir I've tried it before, it works perfectly if you pressed the back button twice you'll get out of the app and the Service started again. but you can still see the app running in the recent screen apps [which means the same as clicking on the home button].
But if you killed/closed the app by pressing long press on the home button and get rid of the app the service is not started again and the app is DEAD.

PsSt:I mean by the recent screen apps [the apps that are still running when press the Home button and you can see them by pressing long press on the home button in old phones and in newer ones by pressing on the square button which is on the bottom left of the phone]
-->here's a screenshot of what I means
29853367_1822490834481423_185688255_n.jpg
 
So have you done exactly what is suggested in that link I gave? Because in that page it says:

"The latter may seem rather peculiar: why do we want to stop exactly the service that we want to keep alive? Because if we do not stop it, the service will die with our app. Instead, by stopping the service, we will force the service to call its own onDestroy which will force it to recreate itself after the app is dead."

I personally haven't had cause to implement this myself, so all I can do is search for resources on the web, like you. I can't give any direct advice.
If the above instructions don't work, I can't suggest anything further, sorry.
 
@LV426
First, I'm making an app that's related to GPS so there's my main app and a background service which works in the background all the time and this's why I want to keep my service works in the background.
Second, as mentioned in android developer site the lifecycle of the app says that if you killed the app any related things will be also killed ! so this's why I can't restart the service from its own onDestroy()
Finally, when I kill the app from the recent screen apps the onDestroy() isn't called... if I can call it that will solve my problem.[I've searched about that and I've found you can call finish() in order to enter onDestroy(), but how would I do that !!! ]

activity_lifecycle.png


 
Hello everyone, I 'm working on a project and I'm supposed to make an app where it has a background service which lasts even the app is closed/killed ! , I've made everything and when I stop the service itself it starts again, but my problem is when I kill the app the service also dies [this's what I want you to help me with] !!

I've tried a looooot of solutions but nothing works
sad.png
sad.png
here's a sample project that I've tried, but it failed.

https://github.com/Jamal-Alkelani/FEService

Pleaseeeeeeeee anyone can help
sad.png


-->All I need if the user close/kill the app I don't want the SERVICE to be killed !!!

Thanks in Advance ♥ ♥

i have the same problem and i use onTaskRemoved too, it didn't called when i swipe to remove on recent. can you help me to solve this
 
Back
Top Bottom