Page 1 of 1
Avoiding reload of App on task switch
Posted: Thu Mar 28, 2013 6:46 pm
by jekyllandhyde
I am starting final phase of testing and have now loaded the App successfully on my iPhone5.
My question is - why is it that when I switch applications and then return to my App does it has to reload from the splash screen all over again? e.g. if you double tap the home button to switch Apps.
Other Apps just freeze and then continue where you left off?
Re: Avoiding reload of App on task switch
Posted: Thu Mar 28, 2013 8:55 pm
by endernafi
LiveCode doesn't support background running officially, yet...
Even it had supported it,
there's no guarantee that iOS wouldn't shut down your app silently while it's in the background.
It's way different than Android.
As the programmer, it's your responsibility to take care of that your app wakes up where it's been left off.
On closeStack -or in any other appropriate handler-
you should save the open card, the variables' values, user's preferences, etc.
On openStack -or any other suitable handler-
you should read the saved parameters and open the app accordingly.
These sentences are directly from
Apple's iOS Guidelines, {sort of

, i've shorten them a bit}
One issue though, the splash screen is deal-breaker here

And the solution is simple,
don't use splash screen.
Put your splash screen into the first card.
Then you can decide whether to show that
splash screen card or not...
Hope it helps,
Best,
~ Ender Nafi
Re: Avoiding reload of App on task switch
Posted: Thu Mar 28, 2013 11:33 pm
by jekyllandhyde
Thanks for the reply, it seem to open a whole can of worms though.
So to make sure I understand you correctly, if I remove the splash screens and add some "onCloseStack" code to freeze everything, then the user can continue where they left off?
Or I can make the splash screen the first card and perhaps use some code to display it for a few seconds?
I don't need it to do anything in the background except just allow the user to view the same card again when they return.
I really have no idea how to do any of this. My App is mostly static information with only a few screens that collect variable information which doesn't really need to be saved.
Any help would be appreciated, or perhaps some sample code if anyone knows how to do this.
Thanks in advance.
Re: Avoiding reload of App on task switch
Posted: Fri Mar 29, 2013 12:30 am
by Dixie
jekyllandhide...
There are three cards in the attached stack... swipe through them, and at whatever card you wish, close the app.. When you open the app again it will open up at the last card you were on...
All the handlers are in the stack script...
Dixie
Re: Avoiding reload of App on task switch
Posted: Fri Mar 29, 2013 2:03 am
by jekyllandhyde
Dixie,
You rock, thanks. I implemented those few lines of stack code and the App goes right back to the screen where I left off in my App.
One other question.
I implemented iOSUINavBarKit.livecode (which uses the standard back menu button at the top)
The script just says "go back" but the problem after suspending the App and re-starting is that it loses track of where "back" is. I assume this is because it wipes out some variable or something when you suspend.
How would I tackle this problem?
Thanks again.
Re: Avoiding reload of App on task switch
Posted: Mon Apr 01, 2013 9:26 pm
by jekyllandhyde
I solved the back button problem.
As a follow up question:
Dixie's method saves the card to a file in documents directory that gets read when the App comes out of it's suspend state. This puts the user back on the same screen they left off which is exactly what I wanted. However I'm wondering if the user removes the app from memory and then starts the App fresh, is there someway to recognize this and have the App ignore the file in the documents directory so that the app loads right from the starting point.
My specific need is that I have a legal screen right after the splash screen which the user has to agree to. If the App is suspended it is bypassed when it comes to the foreground - exactly what I want. However if the user X's the app from the task switcher to remove it from memory and then later re-starts the App I would like to show the legal screen again and start the App fresh.
Thanks for your patience with me, I'm still a beginner.
Re: Avoiding reload of App on task switch
Posted: Tue Apr 02, 2013 6:19 am
by Nakia
Hi,
I actually use the unsupported method of re inserting the exit on suspend key from the pList file to take care of things such as this (Yes it is unsupported and there are some querks) but to answer your question maybe you could use a session time expiry handler:
Like (from my head so may have errors but you should get the idea)
Code: Select all
on closeStack
-- This should take care of placing the time the App closed into a file that could be read on start-up
put the seconds into URL specialFolderPath("Cache") & CloseTime.txt ## Store the time that the App shuts down
end closeStack
Now something like this on startup
Code: Select all
on openStack
-- This should compare the close App time to the Start App time and if the result is more than say 5 minutes launch the Terms and Conditions Card
put URL specialFolderPath("Cache") & CloseTime.txt into tAppCloseTime
put the seconds into tAppStartTime
put tAppStartTime - tAppCloseTime into tTimeBetweenSessions
## Now we do the comparison and action accordingly
if tTimeBetweenSessions > 300 then ## the number here is the session expiry time in seconds
go to card "TermsAndConditions"
end if
end openStack
Re: Avoiding reload of App on task switch
Posted: Wed Apr 03, 2013 4:11 am
by jekyllandhyde
Nakia,
Thanks for posting your approach. Not exactly what I was looking for but I'll experiment with it, it might do the trick.
Re: Avoiding reload of App on task switch
Posted: Wed Apr 03, 2013 7:08 am
by Nakia
I am not really sure there is another way becuase having the app {ExitOnSuspend} (detailed in the pList file) means that when you
close the App from the task bar "memory/whatever" the App will recieve no messages as its already closed.
Maybe I am wrong though...