Page 1 of 1

How does a mobile app keep its "state"?

Posted: Sat Sep 14, 2013 12:20 pm
by garyth123
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.

Re: How does a mobile app keep its "state"?

Posted: Sat Sep 14, 2013 12:44 pm
by Klaus
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:

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
...
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:

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
You get the picture :D


Best

Klaus

Re: How does a mobile app keep its "state"?

Posted: Sat Sep 14, 2013 2:37 pm
by garyth123
That looks great! Thank you Klaus.

Re: How does a mobile app keep its "state"?

Posted: Sun Sep 15, 2013 12:58 pm
by Klaus
Hi Garyth,

my pleasure! :D

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
Best

Klaus

Re: How does a mobile app keep its "state"?

Posted: Mon Sep 16, 2013 4:04 pm
by garyth123
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?

Re: How does a mobile app keep its "state"?

Posted: Mon Sep 16, 2013 4:26 pm
by Simon
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