Android Question Freezing app while phone screen off

erraticless

Member
Hello,

When i run my project (an activity with a service) in release mode in my Samsung Galaxy S20, after about 3 minutes of screen turned off, the complete app just freezes for a few seconds (or even minutes sometimes) until i turn on screen again, and then the program continue working normally. No error, no service destroyed, just continue working.
For testing purpose i made a simple project to log the non-working lapsus. This is a reduced version of a timer project. Inicially i tried a service who restarted every second but it had low precision and didin't like to me. So i decided to run a timer inside of an always-running service, ticking every second, as i show you in the attached file.
In debug mode it works fine, and in release mode using an emulator works well too. The problem only happens when running in my phone with the screen turned off and a few minutes passed in that mode.
I checked all battery and energy saving settings to allow the app run with no restrictions.
I use other timer apps from Google Play without problem.
Is there a better way to approach the issue?
Sorry for my bad english.
 

Attachments

  • TestServiceAlive.zip.zip
    4.3 KB · Views: 97

erraticless

Member
Thanks Erel! It worked well. Is there a better way to develop a timer avoiding the use of PhoneWakeState, preventing the battery draining that continue working while phone sleeping?
 
Upvote 0
Top