Page 2 of 2

Re: running in background

Posted: Mon May 11, 2020 6:15 pm
by SparkOut
jacque wrote: Mon Apr 27, 2020 6:49 am I can't think of an easy solution. Android will shut down your app if it needs the memory (and I think iOS does too,) so if your user doesn't open your app for a while it will stop unless your external device keeps it running. If that's the case, I'm not sure there is an answer. When the OS closes your app you will get a "shutdown" message, but that's the only message LC sends when the app is in the background.

If you have a paid version of LC you are entitled to tech support. You might write to support@livecode.com and ask if they have a solution. If they do, I would love to hear it.
Maybe not a fix for background running, but a pause and resume message may now be possible
LiveCode 9.6.0-rc-1 Release Notes wrote: Android Utilities module Registering for lifecycle SensorEventListener
A new handler AndroidRegisterLifecycleListener has been added that allows for widgets to track application lifecycle events, specifying handlers to be called when the application is paused or resumed. The first parameter is the handler to be called when the application is paused. The second parameter is the handler to be called when the application is resumed. The listener object returned by AndroidRegisterLifecycleListener can be unregistered by calling AndroidUnregisterLifecycleListener, meaning the pause and resume handlers will no longer be called.

Re: running in background

Posted: Mon May 11, 2020 8:16 pm
by jacque
Wow. I've been waiting my whole LC career for those messages!

Re: running in background

Posted: Tue May 12, 2020 9:45 am
by bogs
Wow. I've been waiting my whole LC career for those messages!
**Who are you, and what have you done with Jacque ?

Actually, I suppose that would depend on when you consider Rev(olution) to have changed over to Lc, but 4.5, which is listed on the download pages, has no mobile development tab in the standalone options (although it *does* have the revWeb build option~!!)
Silver and gold, silver and gold...
Silver and gold, silver and gold...
{Beat that for nit-picky Gaddy :P }

** Just some gentle ribbing, I am preparing for school today, and dealing with the children in class always brings out the worst in me.

Re: running in background

Posted: Tue May 12, 2020 11:23 am
by tim2RZ
I can't think of an easy solution. Android will shut down your app if it needs the memory (and I think iOS does too,) so if your user doesn't open your app for a while it will stop unless your external device keeps it running. If that's the case, I'm not sure there is an answer. When the OS closes your app you will get a "shutdown" message, but that's the only message LC sends when the app is in the background.
As I know iOS will do the same, it's not about Android itself.

Re: running in background

Posted: Tue May 12, 2020 5:31 pm
by jacque
bogs wrote: Tue May 12, 2020 9:45 am
Wow. I've been waiting my whole LC career for those messages!
**Who are you, and what have you done with Jacque ?
You obviously have not heard about my time-warp stack which has come up on the mailing list periodically over the years. Aside from some issues with the chronometer, which can occasionally dump you into unexpected time periods, it's fair to say that I sometimes lose track of just exactly when I am. I will have debugged and fixed that problem in a few years.

Re: running in background

Posted: Tue May 12, 2020 5:35 pm
by bogs
So your saying you solved that 3 decades before Hypercard was created, right? :twisted:

Re: running in background

Posted: Tue May 12, 2020 5:42 pm
by trevix
I am not sure how to use this "AndroidRegisterLifecycleListener".
I tested it putting this on the Preopenstack, but it stops the opening script

Code: Select all

...
AndroidRegisterLifecycleListener ApplicationPaused, ApplicationResumed
...
So I guess it is

Code: Select all

on AndroidRegisterLifecycleListener ApplicationPaused, ApplicationResumed

end 

on ApplicationPaused
     do something
end ApplicationPaused

on ApplicationResumed
     do something
end ApplicationResumed
But id doesn't work.
No help on the dictionary.
Android 5.5 , LC 9.6.0 RC1

Re: running in background

Posted: Tue May 12, 2020 5:45 pm
by trevix
Or is this just for Widgets?

Re: running in background

Posted: Tue May 12, 2020 5:49 pm
by trevix
Ah,Aaaah. LCB
I wonder if a library extension can be built with the dictionary example (of LCB)

Re: running in background

Posted: Tue May 12, 2020 6:04 pm
by LCMark
@trevix: Yes this is currently a hook which is only accessible from LCB.

It was motivated by both your FLIC button library (so that we could make it work the same as iOS), and by the barcode scanner where we now use a device's light sensor to perform 'auto' torchMode. (Android strongly suggests that any hardware features not needed whilst the app is in the background be turned off between suspend and resume - iOS does that automatically as the OS doesn't do anything with your app in the background unless you've explicitly asked).

It would be easy enough to wrap in an LCB library which just posts suspend and resume (or similar messages) to enable script to access those lifecycle events...

That being said, we have got an internal patch for suspend/resume for iOS and Android in LCS but it needs a bit more validation (mobile app lifecycle events are a bit of a bed of thorns) and I didn't think it wise to suddenly start firing suspend/resume messages in an RC which never fired on those platforms before! All being we will add engine support for suspend/resume LCS messages on mobile in 9.7 (the dev cycle of which should give people ample time to check what they have in such things currently which might not be appropriate for mobile!).

Re: running in background

Posted: Tue May 12, 2020 6:34 pm
by trevix
Thanks.
iOS does that automatically as the OS doesn't do anything with your app in the background unless you've explicitly asked
In the Fliccase it desn't matter. Pause detection is needed because otherwise external bluetooth device stay connected for days, consuming more battery then needed. It is used to shut off and, eventually, to restablish connection.
And send in time in background (using it like a timer for not-use) doesn't work on iOS