Page 1 of 2

run in background?

Posted: Thu Dec 29, 2011 5:08 pm
by uneu
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?

Re: run in background?

Posted: Thu Dec 29, 2011 6:33 pm
by FourthWorld
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.

Re: run in background?

Posted: Thu Dec 29, 2011 7:45 pm
by uneu
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?

Re: run in background?

Posted: Thu Dec 29, 2011 10:08 pm
by FourthWorld
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.

Re: run in background?

Posted: Sat Jan 28, 2012 6:54 pm
by tzenobite
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?

Re: run in background?

Posted: Sat Jan 28, 2012 7:48 pm
by macnomad2
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

Re: run in background?

Posted: Tue Jan 31, 2012 10:21 pm
by CALL-151
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.

Re: run in background?

Posted: Tue Apr 03, 2012 9:35 pm
by tzenobite
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? :?:

Re: run in background?

Posted: Tue Apr 03, 2012 10:03 pm
by Dixie
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

Re: run in background?

Posted: Tue Apr 03, 2012 10:48 pm
by bn
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

Re: run in background?

Posted: Wed Apr 04, 2012 12:38 pm
by tzenobite
i've already found this in the dictionary.... did you tried it in a real app? running this code in the simulator do nothing...

Re: run in background?

Posted: Wed Apr 04, 2012 12:47 pm
by bn
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

Re: run in background?

Posted: Wed Apr 04, 2012 1:44 pm
by Jellicle
Can't you use local notifications (in v 5.5) to trigger actions at specific times, even if the app is closed?

g

Re: run in background?

Posted: Wed Apr 04, 2012 9:29 pm
by tzenobite
in my stack i have simply:

Code: Select all

on shutDown
  answer "hi"
end shutDown
but the stack says nothing :shock:

Re: run in background?

Posted: Wed Apr 04, 2012 9:52 pm
by tzenobite
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: