Page 1 of 1
Keep app running when screen sleeps?
Posted: Thu Feb 09, 2017 6:59 am
by tjo.mobile
I made a metronome app that plays a click sound at whatever beat per minute the user wants. It works fine but on Android as soon as the screen goes to sleep it stops. I want to use the app with headphones, but having the screen on constantly will kill the battery way too quickly.
Is there a way to keep my app clicking away after the screen goes to sleep on my phone?
Thanks for any advice,
TJ.
Re: Keep app running when screen sleeps?
Posted: Thu Feb 09, 2017 10:48 am
by AxWald
Hi,
no idea if it would play the sound when the fone goes asleep, but to keep an app running I do:
Code: Select all
on upDateClock -- in stack script, started at openstack
if the short name of the topstack = the short name of me then
put the abbr system time into fld "clock_fld" -- a small field displaying the time
end if
send "upDateClock" to me in 20 seconds
end upDateClock
This works great on my tablet with plenty of RAM & a very basic (hand-cleansed) Android - the app can run for days easily, even if I use my map (Scout) & my eBook reader (PocketBook), hear music (Clean music) and run others of my apps meanwhile.
This doesn't work on a stock Android phone with tiny RAM & crammed with manufacturer enforced crap, Android will kill the app due to RAM shortage quickly.
So it's just a question of available RAM. And, of course, a question of if Android will play sounds while sleeping at all :)
Have fun!
Re: Keep app running when screen sleeps?
Posted: Thu Feb 09, 2017 11:28 am
by tjo.mobile
Thanks for the suggestions, much appreciated. My fone in rooted running CyanogenMod, so no extra crap and 4 gigs of RAM, however I'm wondering how long the battery would last.
I'll have to give it a try and find out.
Thanks,
TJ.
Re: Keep app running when screen sleeps?
Posted: Thu Feb 09, 2017 11:59 am
by AndyP
Have a look at mobileLockIdleTimer in the dictionary.
You also have to make sure that Idle Timer is checked in the Android Standalone Settings.
Re: Keep app running when screen sleeps?
Posted: Fri Feb 10, 2017 12:27 am
by tjo.mobile
Thanks Andy!
I was aware of mobileLockIdleTimer, however won't this keep the screen on?
I'm really hoping for a solution that will allow the app to continue to play sounds with the screen sleeping. My main concern is the huge battery drain of having the screen on the whole time the app is running.
Thanks for your help, much appreciated,
TJ.