How does a mobile app keep its "state"?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How does a mobile app keep its "state"?
Hi,
The mobile phone app that I am developing has tap to call/tap to email enabled in fields containing phone numbers or email addresses. This launches the appropriate application on the mobile phone ie the phone or email client. However once the call has been ended/email been sent and I go back to my app I need to login again ie I am not returned to the screen from which I initiated the phone call or email client. This is not what I expected to happen. Can anyone roughly sketch out for me, or give me pointers to where I can find the preferred means of doing this.
Thanks in advance.
The mobile phone app that I am developing has tap to call/tap to email enabled in fields containing phone numbers or email addresses. This launches the appropriate application on the mobile phone ie the phone or email client. However once the call has been ended/email been sent and I go back to my app I need to login again ie I am not returned to the screen from which I initiated the phone call or email client. This is not what I expected to happen. Can anyone roughly sketch out for me, or give me pointers to where I can find the preferred means of doing this.
Thanks in advance.
Re: How does a mobile app keep its "state"?
Hi garyth,
I think the problem is that Livecode iOS apps are not put into background,
when the OS switches to another app, LC apps are quit/terminated.
So next time you go back to your app, you will restart it with all consequences
-> execution of openstack etc handlers = a new log in in your case.
You will need to save the "last state" of your app to file and read it in again
when the app starts again. Know what I mean?
In short pseudo-code:
Then you will need to add a handler to teh preopenstack script that check for that namely file
and if it exists then goes to the "saved" card immediately:
You get the picture
Best
Klaus
I think the problem is that Livecode iOS apps are not put into background,
when the OS switches to another app, LC apps are quit/terminated.
So next time you go back to your app, you will restart it with all consequences
-> execution of openstack etc handlers = a new log in in your case.
You will need to save the "last state" of your app to file and read it in again
when the app starts again. Know what I mean?
In short pseudo-code:
Code: Select all
...
## We will open the TELEPHONE or EMAIL app soon:
put the number of this cd into url("file:" & specialfolderpath("documents") & "/last_card_before_quit")
## Now DIAL a phone number or open the EMAIL app
...
and if it exists then goes to the "saved" card immediately:
Code: Select all
on preopenstack
put specialfolderpath("documents") & "/last_card_before_quit" into tLastState
if there is a file tLastState then
put url("file:" & tLastState) into tTargetCard
go cd tTargetCard
else
## "REGULAR" app start procedures here...
end if
...
end preopenstack
Best
Klaus
Re: How does a mobile app keep its "state"?
That looks great! Thank you Klaus.
Re: How does a mobile app keep its "state"?
Hi Garyth,
my pleasure!
Maybe it is a good idea to also DELETE that file after you have used it:
Best
Klaus
my pleasure!
Maybe it is a good idea to also DELETE that file after you have used it:
Code: Select all
on preopenstack
put specialfolderpath("documents") & "/last_card_before_quit" into tLastState
if there is a file tLastState then
put url("file:" & tLastState) into tTargetCard
go cd tTargetCard
## OK, the file has done what it should, no need for it anymore!
DELETE file tLastState
else
## "REGULAR" app start procedures here...
end if
...
end preopenstack
Klaus
Re: How does a mobile app keep its "state"?
Unfortunately this is not working for me. I have tried it running as as a LC stack running in the IDE, closing the stack on the necessary card and then launching the stack again. It always opens at the first card. I can see the file last_card_before_quit being created, and the tTargetCard variable contains the correct card number, but go to tTargetCard doesn't appear to be doing its job. Any ideas what I'm leaving out?
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: How does a mobile app keep its "state"?
Hi Gary,
For debugging I'd just place a "go card 2" in the pre/open stack/card and see which one it picks up. You might have something in the scripts which prevent it from continuing. Placing it as the last line of the handlers will ensure after the other scripts are done it will get the last word in. (errr, unless you have an "exit this handler" before it).
Simon
For debugging I'd just place a "go card 2" in the pre/open stack/card and see which one it picks up. You might have something in the scripts which prevent it from continuing. Placing it as the last line of the handlers will ensure after the other scripts are done it will get the last word in. (errr, unless you have an "exit this handler" before it).
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!