Keep app running when screen sleeps?

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tjo.mobile
Posts: 18
Joined: Tue Oct 25, 2016 8:09 pm

Keep app running when screen sleeps?

Post by tjo.mobile » Thu Feb 09, 2017 6:59 am

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.

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Keep app running when screen sleeps?

Post by AxWald » Thu Feb 09, 2017 10:48 am

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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

tjo.mobile
Posts: 18
Joined: Tue Oct 25, 2016 8:09 pm

Re: Keep app running when screen sleeps?

Post by tjo.mobile » Thu Feb 09, 2017 11:28 am

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.

AndyP
Posts: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Keep app running when screen sleeps?

Post by AndyP » Thu Feb 09, 2017 11:59 am

Have a look at mobileLockIdleTimer in the dictionary.

You also have to make sure that Idle Timer is checked in the Android Standalone Settings.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

tjo.mobile
Posts: 18
Joined: Tue Oct 25, 2016 8:09 pm

Re: Keep app running when screen sleeps?

Post by tjo.mobile » Fri Feb 10, 2017 12:27 am

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.

Post Reply

Return to “Android Deployment”