Android Question Foreground Services

irobots

Member
Hi,
I was wondering if foreground services continue to work even after the phone is in sleep mode. I want to make an app which is able to continue working even after the phone if off and sleeping but dont want to prevent it sleeping all that time. Just wanted to clear that up before I purchase the software.

Thanks,
Irobots
 

thedesolatesoul

Expert
Licensed User
Longtime User
A foreground service will only prevent the service from being killed, it should not prevent sleeping.
You can use WakeState locks to prevent it from sleeping when you want to.
There are many other ways you can use a service without even needing it to be foreground, but it depends on how you want to use it.
 
Upvote 0

irobots

Member
Thank you for the response. I understand the use of wakestate but I was more specifically wondering if there is a type of service which could run when the phone is sleeping as calling wakestate continuously would most likely drain the battery very fast.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…