running in background

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

RobertC
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Feb 04, 2007 3:43 pm

running in background

Post by RobertC » Mon May 06, 2019 7:17 pm

Hi,
I'm writing an "Alarm" program (desktop). It compares the current time with that of the next alarm and sounds an alarm when that time passes. This is done by sending a check message every second. So far so good. But problems start when the user is doing other things than staring at the alarm program. And she usually does.

On Mac OS:
  1. when the program is not the active one, its clock keeps ticking. This does not pose a problem though I have to add an Applescript command to make the program the active one at the moment the alarm time passes,
  2. when the computer is put to sleep, the program stops, i.e. does not keep running in the background. I do not know how to deal with this other than by using an OS system command to schedule a wake-up, and that seems to work.
  3. when the program is hidden, e.g. by going to another program's window while holding the option-key or by choosing "Hide Others" from another program, the alarm program also stops. I don't know how to deal with that. The machine is not asleep and the focus is on another program and the alarm program is not visible.
So the last point is really the question.
Is it possible to run a program in the background?
The Old Rant Robert.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: running in background

Post by dunbarx » Mon May 06, 2019 9:41 pm

Hi.

A timer running in LC will continue unfettered when other apps are in front, regardless of whether LC itself is hidden or not. May I assume you are sending a message in time to do this?

Similarly if the machine is asleep. When it wakes up, the timer will have advanced as if nothing happened.

What are you seeing?

Craig Newman

RobertC
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Feb 04, 2007 3:43 pm

Re: running in background

Post by RobertC » Tue May 07, 2019 7:26 am

Hi Craig,

Thanks.
I think I made a stupid mistake: for testing I had somewhere

Code: Select all

…if the optionkey is up then send "…" to me in 1 second
so that I could stop the clock by pressing option briefly.
However, obviously if I hide the program by holding down the optionkey while clicking elsewhere, the sending also stops.

So, yes, I think it works.
Sorry.
Take this topic away completely?
The Old Rant Robert.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: running in background

Post by bogs » Tue May 07, 2019 12:31 pm

RobertC wrote:
Tue May 07, 2019 7:26 am
Take this topic away completely?
I would vote no, I see it as a good example of having to think through a problem, as well as an aid to those learning who we never hear from (forum lurkers).

I have got a few posts here showing a problem resolved where I thought it was a problem with the IDE/language/something else, but it turned out to be similar to this issue, The one that I remember best is a stack I had written in 6, opened in 8 or 9, and then couldn't reopen in 6 even though I did not save it in a later version.

In that case, the problem had been that I had included a 'save this stack' line in the close messages which I didn't catch or even think of since all my versions have the preference set to save in the format it was written in. The later versions, however, can only save back so far (I think to 7), and that was why I wasn't able to open it again in 6.x.

I was lucky in that I alway make multiple backups at every stage, and was able to restore what i needed once I understood the problem (thanks again to Panos for that!) :D
Image

RobertC
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Feb 04, 2007 3:43 pm

Re: running in background

Post by RobertC » Tue May 07, 2019 3:05 pm

Agreed, leave it as example; good idea.

When the program is finished I'll post it here too then. Plus its documentation.
The Old Rant Robert.

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: running in background

Post by tomBTG » Tue May 07, 2019 3:11 pm

One other option for you... Make the alarm stack small and set it to open as a palette window that floats above all other applications.
-- Tom B.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: running in background

Post by dunbarx » Tue May 07, 2019 3:57 pm

Make the alarm stack small and set it to open as a palette window
Yep, that will keep it in front, if that is important, but the original issue was different, that the timer stopped.

Craig

RobertC
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Feb 04, 2007 3:43 pm

Re: running in background

Post by RobertC » Wed May 08, 2019 7:34 am

Thanks for the suggestion TomBTG, but that was already done.

There exists in fact an excellent gadget that does the required alarm functions, but the developers have not updated it for at least five years, the site seems dead and it will stop running when Apple abandons 32bit.

Since we're on ergonomics, there are a few other considerations:

- spaces: I did find a way for it to be present on all spaces, as that is a per-app OS preference, but it was not obvious in the beginning,

- sound: one issue is that the app must use its own sound volume setting when sounding an alarm, then go back to the previous one. That's easy too, so no worries.

- But: Apple no longer make screens, and a nice new screen we recently bought, a Samsung extra-wide and curved (SAMSUNG LC34J791WTUXEN), could not be controlled from the computer. Which is a laptop that lives behind the screen with the lid closed, and only has USB-C sockets. It's hell if you can't control the brightness and the volume from the keyboard…
The Samsung had USB-C input, but nothing worked. Then after some search we found there is DDC/CI, a sort of control standard. Screens must have some electronics built-in and some control connection such as HDMI, DisplayPort, USB or USB-C that can carry the control signals. The Samsung did not have the electronics. We then found a Philips, (PHILIPS 349X7FJEW/00) exactly the same extra-wide, curved screen (somewhere I read the LCD slab itself is actually made by Samsung) which does have the DDC/CI electronics. It sort of works, but it came with drivers only for Windows. Yet another freeware gadget to be installed for the brightness control. But he sound still does not go through the display cable, it has to come out of the 3.5mm audio jack of the computer (fortunately Apple has not yet removed that one) and then go into the 3.5mm audio input jack which the screen fortunately has. And that sound level can be controlled from the keyboard.
But what a mess.

And finally, if you have not stopped reading by now, another disaster of a different nature is about to happen: when 32bit is no longer supported by macOS, I will lose Numbers'09. The newer version (2013) had a number of functions removed and also adapted to the iPad touch interface, making everything BIG and no longer having floating inspectors. It's ergonomic hell. I'm laying a road to a LiveCode spreadsheet, but that is not obvious at all. Going back to Excel is not an option once you're used to multiple independent, sorting-proof tables with header and footer rows.

:-(
The Old Rant Robert.

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: running in background

Post by trevix » Sat Apr 25, 2020 3:01 pm

I am going back to this old thread because I noticed one thing:

- I am running a time counter (send ..in 1 seconds) on hardware iOS and Android.
- On iOS the counter stops when the App is in background.
- On Android the counter keeps running when the App is in background.

Beside trying to have a consistent UI on both platforms, my intent is that the counter should keep running also on iOS.
Is there any other way I can achive this?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: running in background

Post by tomBTG » Sat Apr 25, 2020 3:32 pm

What version of iOS are you testing against? I don't know much about mobile dev, but seem to recall that multitasking was missing in earlier versions of iOS and that feature was added to iOS releases. (Multitasking should let your clock keep on ticking.)
Tom B.

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: running in background

Post by trevix » Sat Apr 25, 2020 4:13 pm

iOS 13.3.1
And I don't understand it either. In the iOS standalone settings of LC 9.6.0Dp4 the option "enable background execution" is not there anymore.
It is there up to LC 9.6.0 dp2.
Am I missing something?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: running in background

Post by jacque » Sun Apr 26, 2020 4:45 pm

IOS now keeps all apps in the background. That missing option has been deprecated, and including it in the app now causes Apple to reject the submission which is why LC removed it.

But it sounds like a background app in memory doesn't actually run, or else there's some other reason why the timer doesn't update. You may have to store the current time in a variable every second so that when the app is frontmost again you can calculate the difference and resume where it left off.

It would be nice if LC could let us know when a mobile app goes into the background, but it doesn't.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: running in background

Post by trevix » Sun Apr 26, 2020 10:26 pm

You are correct but Jacque. Thanks for the info.
As I understand, sooner or later we will have the background detection on Android and iOS (ok, there is mergNotify for this last).
My problem tough is slightly different:
I have an external device, connected with bluetooth, that unfortunately keeps the connection "on" when the App goes to BK, on both platform, consuming battery (mobile users don't care of exiting from App, so this could last for days).
On iOS, using mergNotify, I could teoretically detect when the App goes to BK and, say, close the connection after 20 minutes of inactivity. But this is not possible since the send in time does not work when the App is in BK. It's a nightmare.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: running in background

Post by jacque » 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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

trevix
Posts: 958
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: running in background

Post by trevix » Tue Apr 28, 2020 6:56 pm

Can some please confirm that send in time does NOT run when the app is in background (iOS)?
Somehow I think to remember that it wasn't like this, before this last round of LC versions.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”