Running in Background

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Running in Background

Post by endernafi » Mon Aug 20, 2012 4:23 pm

Hi there Dear LiveCoders,

Is it possible an app written in LiveCode to run in background, like a music player for example?
And more important, is it possible the LiveCode apps to continue where they have been left off?
All my apps are starting all over again when they are clicked.

Does anyone know a tutorial about or
could someone put a simple sample stack here related to one of these two issues?
I really don't know even where to start :oops:
And I'm sure there are many who need a tutorial or sample like I do.


Kind Regards,



~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

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

Re: Running in Background

Post by Dixie » Mon Aug 20, 2012 4:37 pm

Hi...

I have attached a stack for you to look at... It contains 3 cards... move between the cards and then close the stack. When you open the stack again it will go to the card that you were on before the stack was closed. All the handlers are in the stack script.

be well

Dixie
Attachments
swipe2.livecode.zip
(2.09 KiB) Downloaded 231 times

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Running in Background

Post by Klaus » Mon Aug 20, 2012 4:39 pm

Hi Ender,
endernafi wrote:Is it possible an app written in LiveCode to run in background, like a music player for example?
no, LiveCode does not support this!
endernafi wrote:And more important, is it possible the LiveCode apps to continue where they have been left off?
Yes, but need a bit of work :D

Save the last "state" of your app as a text file in the users documents folder when it closes
and read it back again when the app starts again.

Very simplistic example if you only want to lead the user to the card he last visited (in pseudocode :D )
1. when the app starts:

Code: Select all

on preopenstack
  put specialfolderpath("documents") & "/last_state.txt" into tLaststate

  ## No file? 
  ## Then this is obviously the first start of the app ever
  if there is not a file tLaststate then
    exit openstack
  end if

  ## File found, check where we have been the last time
  ## In this example I only save the number of the last card the user has visited
  put url("file:" & tLaststate) into tTargetCard
  go cd tTargetCard
end openstack
2. when app quits (closestack?)

Code: Select all

on closestack
    put specialfolderpath("documents") & "/last_state.txt" into tLaststate
    
  ## Now save the current card number:
  put the num of THIS cd into url("file:" & tLaststate)
end closestack
You decide what to save, like contents of fields, states of checkboxes/radiobuttons etc...
You get the picture :D


Best

Klaus

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Contact:

Re: Running in Background

Post by endernafi » Mon Aug 20, 2012 4:45 pm

Thanks guys,

That's what I needed, an anchor point to start :)
Many thanks, both of you...


Regards,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Post Reply