Android Question Service in Foreground with Partial Lock

bocker77

Active Member
Licensed User
Longtime User
I have a question if my idea of an app is feasible. I want to obtain GPS coordinates continuously so that when driving a car at high speeds say 55 MPH it is able to detect when a coordinate is in a range. I tested it out by going to a spot that I want to detect but the phone went into sleep mode/locked beforehand and nothing was detected. When I take it out of sleep mode and unlock it, it works. Also if I force the screen on continuously, if possible, I know that there will be issues with draining the battery. I read up on running a phone while phone is plugged into a power source could have a negative impact on its life. But also read that on some devices including phones it doesn't matter, like my tablet which I do all the time. If anyone can shed some light on this it would be greatly appreciated.

Thanks in advance to anyone who responds. And a special thanks to anyone with a solution.
 

roumei

Active Member
Licensed User
I use awake.KeepAlive in my hiking app to prevent the phone from going to sleep as long the map is shown and GPS is running:
B4X:
Dim awake As PhoneWakeState
awake.KeepAlive(False) ' to keep the app alive without a bright screen
awake.ReleaseKeepAlive ' allow sleep again
I wouldn't worry too much about draining the battery. If the user wants to use the app exactly for its purpose, it's probably OK. My app runs on a Motorola g8 power for more than 12 hours with the display and GPS switched on.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Thanks roumei, it looks like I solved the sleep lock issue by changing where I start the service. I give a warning about battery usage in the app so I cover that. My thoughts that if someone is on a long ride in a car with this app running that a solution would be to plug it into the car's power source so that they don't miss a call or message because of it. I also like the KeepAlive statement.

Thanks again.
 
Upvote 0
Top