Can't save to Android

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Can't save to Android

Post by simon.schvartzman » Fri Jul 27, 2018 4:14 pm

Hi guys, I've reviewed all the posts (and lessons, and documentation) about the subject and still can't figure out what am I doing wrong. Have been fighting for 3 hours before posting.
BTW it works fine on iOS.

Help please, I need to make a quick demo to a prospect.

This is my code, just trying to save some config. info when the App closes and be able to retrieve it when the App opens

Code: Select all

on CloseCard
   put specialFolderPath ("documents") & "/" & "setup.txt" into tMyPath
   put field DriverID into line 1 of URL ("file:" & tMyPath)
end CloseCard

Code: Select all

on OpenCard
      set the defaultFolder to specialFolderPath("documents")
      put the  line 1 of URL ("file:setup.txt") into field DriverID
end OpenCard
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: Can't save to Android

Post by Klaus » Fri Jul 27, 2018 4:22 pm

Hi Simon,

the scripts look OK, just to be sure tMyPath is either declared LOCAL or GLOBAL?


Best

Klaus

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Fri Jul 27, 2018 4:31 pm

Hi Klaus, many thanks for your prompt answer.

tMyPath was not declared neither Local nor Global (my fault). It seems it doesn't make any difference, at least on iOS.

I declared it Local now, but still no joy on Android.

This is the first time I'm trying to deploy an App on Android and I wonder if there is something I'm missing on the Standalone configuration or even in the device configuration...
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: Can't save to Android

Post by Klaus » Fri Jul 27, 2018 4:36 pm

Hi Simon,

sorry, that was nonsense :oops: , it is very hot over here in germany, I have 33° Celsius in my room...
And it is even hotter outside...

Well, you could and should check "the result" after writing to file:

Code: Select all

on CloseCard
   put specialFolderPath ("documents") & "/setup.txt" into tMyPath
   put field DriverID into line 1 of URL ("file:" & tMyPath)
   if the result <> EMPTY then
     answer "Error:" & CR & the result
  end if
end CloseCard
Maybe that will give us a hint on what is going wrong.


Best

Klaus

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Fri Jul 27, 2018 4:49 pm

Klaus I live in Brazil and I know what you mean...No Air Conditioning in Germany? :D

I guess "answer" doesn't work on CloseCard, does it?

But I got another hint, if I put the same script inside a button script instead of on CloseCard then it works!!!

Does it help?
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: Can't save to Android

Post by Klaus » Fri Jul 27, 2018 5:29 pm

Hi Simon,
simon.schvartzman wrote:
Fri Jul 27, 2018 4:49 pm
Klaus I live in Brazil and I know what you mean...
oh, then you are more or less accustomed ot these temperatures, but we poor and pale europeans...
simon.schvartzman wrote:
Fri Jul 27, 2018 4:49 pm
No Air Conditioning in Germany? :D
Sure, but not in my house...
simon.schvartzman wrote:
Fri Jul 27, 2018 4:49 pm
I guess "answer" doesn't work on CloseCard, does it?
That should work! (Famous last words :D )
simon.schvartzman wrote:
Fri Jul 27, 2018 4:49 pm
But I got another hint, if I put the same script inside a button script instead of on CloseCard then it works!!! Does it help?
Yes, in puzzling me even more!

Can't you use a "closefield" handler for field "DriverID" with that script?
At least worth a try.


Best

Klaus

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Fri Jul 27, 2018 6:17 pm

Klaus, I guess nothing is working on my closeCard handler.

Neither the "answer" nor the "save", nothing.

The point is I have this App with just on Card on it, meaning I'm closing the Card when I close the App, not sure if that could be the issue.
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: Can't save to Android

Post by Klaus » Fri Jul 27, 2018 6:19 pm

Hm, you could try to save:
"on closestackrequest" (dont forget to PASS closestackrequest!)
And "on closefield" if not tested yet.

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Fri Jul 27, 2018 8:41 pm

Klaus, none of the options did work.

I guess the problem is related with closing the App via the Android close (similar to pushUp on iPhone) instead of through the App itself (not sure if I'm making myself clear enough...)

Anyway for now I found a workaround using a button to save...

I could send the full App for your review if it would help. Just let me know.

Regards and many thanks for your support.
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: Can't save to Android

Post by Klaus » Sat Jul 28, 2018 2:21 pm

Hi Simon,

ususalls I 'm the first shouting "Send me the stack!", but since i do not develop for mobile,
I don't even own a cellphone or any other device, this would not be of much use,
since this will surely work in the IDE.

No idea of Android hardware, but this is not the BACKKEY?
If yes, then you could script this event, check the dictionary for "backKey".

We also have these "Android hardware button" events:
menuKey
searchKey
in LC if that helps...


Best

Klaus

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Sat Jul 28, 2018 2:53 pm

Klaus many thanks for your suggestions, unfortunately none of them did the trick.

Anyway since I found a good workaround I will close the subject for now. May be later I will open a bug report for Panos to have a look at it.

Have a nice (hot) weekend.
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Can't save to Android

Post by jacque » Sat Jul 28, 2018 5:33 pm

How are you closing the app? BackKey will give you a message you can trap, and I'd add the save routine to that. You will not get any messages from the Home key or the app switcher so you can't rely on those. Finally, Android never quits an app, it always retains it in the background until it needs the RAM, which is why no closecard is sent.

Try adding the save to a closefield handler, you should be able to catch most changes that way.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Sat Jul 28, 2018 5:46 pm

Thanks Jacque, you enlighten my with "You will not get any messages from the Home key or the app switcher so you can't rely on those. " I was trying to save when the user closed the App with the app switcher. Will use the closefield as Klaus and you suggested

Regards
Simon
________________________________________
To ";" or not to ";" that is the question

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Can't save to Android

Post by simon.schvartzman » Sun Jul 29, 2018 6:40 pm

@jacque, let me ask you something, is there any way to trap the App Switcher? I have this app where the user is constantly sending his location to a server. I'd like to be able to identify when the user closes the app even if he does so via the App Switcher. Any ideas as how can I accomplish this?

Thanks
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Can't save to Android

Post by jacque » Sun Jul 29, 2018 8:35 pm

simon.schvartzman wrote:
Sun Jul 29, 2018 6:40 pm
@jacque, let me ask you something, is there any way to trap the App Switcher? I have this app where the user is constantly sending his location to a server. I'd like to be able to identify when the user closes the app even if he does so via the App Switcher. Any ideas as how can I accomplish this?
I wish we could, but no messages are sent so there is nothing to trap. What we need are suspend and resume messages and there is a request for that, but apparently it is difficult to implement and so far there is no progress. Mark Waddingham said a long time ago that they did attempt it but couldn't make it work.

Due to the fact that Android never quits an app, it isn't really "suspended" or quit unless you specifically call the "quit" command. Android OS handles memory usage and if an app requires more free RAM that is currently available Android will unceremoniously dump background apps as needed. Your app can disappear at any time, so the only solution (and the way Android says you should handle things) is to constantly save the current state of the app so that it can resume where it left off if that is important to its functioning.

If the app does remain in RAM then it will automatically pick up where it was before, so you really only need to reinstate everything on a preOpenStack or openStack handler (when a suspended app resumes, there are no pre- or open- messages because nothing has changed.) But you do need to save the state repeatedly in case the app needs to restart.

You can see how it works by launching your app, going back to the launcher, and then immediately reopening the app. Unless your launcher does something RAM-intensive, your app should still be there just as it was. Now open Chrome browser and load a number of different web sites (which usually takes enough RAM to quit background processes.) Then reopen your app and chances are it will load as new again.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”