Android Tutorial Creating a sticky service - long running background tasks

RichyK68

Active Member
Licensed User
Longtime User
They do work, but they get killed when memory gets low and can never restart from what I can tell due to Lollipop's shockingly ruthless memory management (unless the user manually re-opens the app).

Is there a workaround? I want my foreground service to restart if it gets killed. Else it defeats the point of the app. And just makes Android useless in many ways for a developer when Google make these horrible decisions.

Richy
 

Daniel-White

Active Member
Licensed User
Longtime User
Among "StartServiceAT" , Service.StartForeground and Sticky service.

Which one save more life time battery, ?, an example for GPS tracking APP (take only GPS data each 2 minutes), and Why is the best approach.?

Thanks you so much
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
an example for GPS tracking APP
Hello,
In that case I would say : PhoneWakeState and FusedLocationProvider because the data will be available immediately.
But if you don't care waiting, StartServiceAtExact
 

Daniel-White

Active Member
Licensed User
Longtime User
Thanks Lemonisdead. I am actually using FusedLocation lib, and work great, and using StartServiceAT to schedule it to work each 2 minutes. However I am all ear to any other approach . Or I am in the correct path.
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
StartServiceAT to schedule it to work each 2 minutes.
It is a good starting point but I wonder if you wouldn't have less energy consumption by acquiring a partial lock and letting FusedLocation check every two minutes. Just a thought because it seems (for me, for my understanding) to be a heavier process to start a service each two minutes (short delay). But it should be interesting to prototype both strategies and compare the results
 

cxdzbl

Active Member
Licensed User
Recently, I've read about service on the Internet, and now it's hard to keep it running in the background. As the Android version improves, all sorts of methods fail. My version of the Samsung S7, Android 7, recently upgraded after the discovery, I think in the Service_Destroy to run another service to listen to each other seems to have no reaction, close the application in the list of recent operation, service was killed and the Service_Destroy code is not executed. I wonder if b4a has an effective way to make service live a little more?
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…