How does a mobile app keep its "state"?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Locked
garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

How does a mobile app keep its "state"?

Post by garyth123 » Sat Sep 14, 2013 12:20 pm

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.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Sat Sep 14, 2013 12:44 pm

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

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

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

Post by garyth123 » Sat Sep 14, 2013 2:37 pm

That looks great! Thank you Klaus.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Sun Sep 15, 2013 12:58 pm

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

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

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

Post by garyth123 » Mon Sep 16, 2013 4:04 pm

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?

Simon
VIP Livecode Opensource Backer
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"?

Post by Simon » Mon Sep 16, 2013 4:26 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Locked

Return to “Summer School 2013”