run in background?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

uneu
Posts: 96
Joined: Wed Dec 07, 2011 11:45 pm
Contact:

run in background?

Post by uneu » Thu Dec 29, 2011 5:08 pm

Can an app be made to run in background, i.e. user starts app then closes it and/or switches off iPhone with slider and app still runs and does things specified at specified time intervals? Also, if possible, how to minimize battery usage?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: run in background?

Post by FourthWorld » Thu Dec 29, 2011 6:33 pm

uneu wrote:Can an app be made to run in background, i.e. user starts app then closes it and/or switches off iPhone with slider and app still runs and does things specified at specified time intervals? Also, if possible, how to minimize battery usage?
Most tasks can be done in the background on Android, but iOS limits the range of background tasks to a very few specific operations.

The range of tasks an app can do in the background on iOS has increased considerably in v5 over v4, but is still quite limited.

Given the ever-changing specs with iOS, you'll need to refer to the docs at developer.apple.com to learn which specific tasks are allowed in the background at this time.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

uneu
Posts: 96
Joined: Wed Dec 07, 2011 11:45 pm
Contact:

Re: run in background?

Post by uneu » Thu Dec 29, 2011 7:45 pm

Thanks, so just iOS restrictions apply. Is there anything that has to be specified in LiveCode or do those tasks that can run in background do so regardless once they are running?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: run in background?

Post by FourthWorld » Thu Dec 29, 2011 10:08 pm

uneu wrote:Thanks, so just iOS restrictions apply.
There are also some restrictions for background processes on Android as well, since any mobile OS will need to monitor processes to maintain good memory and power management. iOS is by far the more restrictive of the two, but a developer will want to be aware of such limitations and account for them in the program as much as possible.

It's hard to guess exactly how such limitations can come into play with your specific app without first knowing the details of what your app wants to do in the background, what it needs to do, how it might be able to take advantage of suspend/resume schemes if the OS kills it while its in the background, and the specific limitations of each OS.

To learn more you may want to review the LiveCode docs for those platforms carefully, and consider reviewing the sections of the Apple and Android dev sites which may apply to what you want to do.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

tzenobite
Posts: 57
Joined: Sun Dec 04, 2011 3:59 pm

Re: run in background?

Post by tzenobite » Sat Jan 28, 2012 6:54 pm

i tried a very simple experiment: a stack with 1 button and 1 script that increase a field's value by 1 every second
i run the stack in the simulator then i click the home button, then i open the stack again and the field has "0" in it
so, a simple script inside the stack don't run on background, i was planning to make an app working mostly in background...i have to trash the idea?
how many hypercardist are needed to change a light bulb? one to actually do it while at least a dozen more are finding out a slightly different way to do it

proudly hypertalking since 1989

macnomad2
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 63
Joined: Sat Oct 28, 2006 10:04 pm

Re: run in background?

Post by macnomad2 » Sat Jan 28, 2012 7:48 pm

LC does not allow for multitasking, so to me background is not possible. Whenever you come back to your app the engine restarts and your app also.
Am I wrong
I would also love these features in LC on iOS

CALL-151
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 206
Joined: Wed Oct 20, 2010 11:00 am

Re: run in background?

Post by CALL-151 » Tue Jan 31, 2012 10:21 pm

macnomad2 wrote:LC does not allow for multitasking, so to me background is not possible. Whenever you come back to your app the engine restarts and your app also.
Am I wrong
I would also love these features in LC on iOS
You are not wrong.

tzenobite
Posts: 57
Joined: Sun Dec 04, 2011 3:59 pm

Re: run in background?

Post by tzenobite » Tue Apr 03, 2012 9:35 pm

so, how i can trap the "go to homescreen" action on the iphone? the stack actually is close instead of paused, like others app, and i have to bring the user back where he/she was at the moment s/he pushes the home button... how to save the app "state" (as text) just the moment the app is closing? :?:
how many hypercardist are needed to change a light bulb? one to actually do it while at least a dozen more are finding out a slightly different way to do it

proudly hypertalking since 1989

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: run in background?

Post by Dixie » Tue Apr 03, 2012 10:03 pm

Hi...

When your stack is closing.. then write the number of the card that you are presently on to a file in the documents folder... then when the app is started again, read the file, which will contain the number of the card you were on before the stack closed and then go to it...

I use this a lot

be well

Dixie

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: run in background?

Post by bn » Tue Apr 03, 2012 10:48 pm

Hi Tzenobite,

I use on

Code: Select all

shutDown
   -- save what you want to save
end shutDown
in a stack script. Works well if someone presses the home button.

Kind regards

Bernd

tzenobite
Posts: 57
Joined: Sun Dec 04, 2011 3:59 pm

Re: run in background?

Post by tzenobite » Wed Apr 04, 2012 12:38 pm

i've already found this in the dictionary.... did you tried it in a real app? running this code in the simulator do nothing...
how many hypercardist are needed to change a light bulb? one to actually do it while at least a dozen more are finding out a slightly different way to do it

proudly hypertalking since 1989

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: run in background?

Post by bn » Wed Apr 04, 2012 12:47 pm

Hi tzenobite,

what is your code?

Just saw that in my code example above of course it has to be

Code: Select all

on shutDown
  -- code
end shutDown
This worked for me in the simulator and on a real device. Actually it was the only way I found to trap for the shutting down of the app by pressing the Home button. This was a while back and may have changed.

Kind regards

Bernd

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: run in background?

Post by Jellicle » Wed Apr 04, 2012 1:44 pm

Can't you use local notifications (in v 5.5) to trigger actions at specific times, even if the app is closed?

g
14" MacBook Pro
Former LiveCode developer.
Now recovering.

tzenobite
Posts: 57
Joined: Sun Dec 04, 2011 3:59 pm

Re: run in background?

Post by tzenobite » Wed Apr 04, 2012 9:29 pm

in my stack i have simply:

Code: Select all

on shutDown
  answer "hi"
end shutDown
but the stack says nothing :shock:
how many hypercardist are needed to change a light bulb? one to actually do it while at least a dozen more are finding out a slightly different way to do it

proudly hypertalking since 1989

tzenobite
Posts: 57
Joined: Sun Dec 04, 2011 3:59 pm

Re: run in background?

Post by tzenobite » Wed Apr 04, 2012 9:52 pm

just tried: for some reasons i ignore, the stack can write to a file while closing but can't do something "physical" like an anwer dialog :roll:
anyway, this will work for me, thanks again to all you nice people :wink:
how many hypercardist are needed to change a light bulb? one to actually do it while at least a dozen more are finding out a slightly different way to do it

proudly hypertalking since 1989

Post Reply