Saving a data stack in android

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Saving a data stack in android

Post by keith.izatt » Mon Dec 15, 2014 5:02 am

I have created a launcher stack that opens an application stack. I am able to access the application stack on an android device, but am not able to save the stack after I modify it. I can modify it, but can not find the right syntax to save the modifications.

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Mon Dec 15, 2014 5:15 am

Is it possible to save a substack(appstack) of a mainstack(launcherstack) in Android?

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Saving a data stack in android

Post by sefrojones » Mon Dec 15, 2014 5:45 am

Keith,

Welcome! Stacks included in the "Copy Files" pane will end up in specialFolderPath("engine"), you will need to copy it to specialFolderPath("documents") before you will be able to save them. This lesson isn't specifically about saving stacks, but should get you started on your way:

http://lessons.runrev.com/m/4069/l/1522 ... ile-device


Write back whenever you get stuck. This forum is filled with helpful people. :D

--Sefro

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Mon Dec 15, 2014 6:22 am

thanks for your response. I have copied the stack to my documents folder, but do not know how to initiate a save of any modifications to my stack. Here is my code that saves it to my documents.

Code: Select all

on openstack
   set the defaultfolder to specialfolderpath ("Documents")
   if there is not a file "Appstack.livecode" then
      put the filename of this stack into masterfile
      set the itemdelimiter to "/"
      put "Appstack.livecode" into the last item of masterfile
      --put specialFolderPath ("engine") & "/AppStack.livecode" into masterfile
      put specialFolderPath ("Documents") & "/AppStack.livecode" into appfile
      put URL ("binfile:" & masterfile) into URL ("binfile:" & appfile)
   end if
   go stack specialFolderPath ("Documents") & "/AppStack.livecode"
   answer the filename of this stack--shows that it is in my documents folder
end openstack
Now i need the syntax to save changes to the appstack. I have tried many variations of this in a button in the stack, but nothing seems to save my changes. This is one example of something I tried.

Code: Select all

on mouseUp
   put specialFolderPath("Document") & slash & "Appstack.livecode" into appfile
   put stack "appstack.livecode" into URL("binfile:" & appfile)
end mouseUp
Here is another attempt of the script in a save button

Code: Select all

save stack "appstack.livecode" into URL("binfile:" & specialfolderPath("documents") & slash & "appstack.livecode")

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

Re: Saving a data stack in android

Post by Klaus » Mon Dec 15, 2014 1:12 pm

Hi Keith,

like most things in Livecode this is a "slap-on-the-forehead" thingie:
...
save stack "appstack"
## or whatever your stack is named in Livecode, NOT the filename!
...
:D

Important hint:
ALWAYS use parens when concatenating file- and objectnames!
....
### go stack specialFolderPath ("Documents") & "/AppStack.livecode"
go stack (specialFolderPath ("Documents") & "/AppStack.livecode")
...


Best

Klaus

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Mon Dec 15, 2014 4:58 pm

Thanks for the reply. Unfortunately, this still does not save the changes to the stack. I have a field on the stack and I type into it then click on the save button. When I close the application and open it again, the text that I had typed in is not there.

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

Re: Saving a data stack in android

Post by Klaus » Mon Dec 15, 2014 6:12 pm

Hi Keith,

hm, that is the way it is supposed to work!? Maybe your app did not really get updated?
Sorry, no experience with Android stuff...


Best

Klaus

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

Re: Saving a data stack in android

Post by jacque » Tue Dec 16, 2014 8:59 pm

Is it possible that the original copy of the stack is open in memory when you open the copied one? If so, there would be two copies in memory at the same time and the engine may be trying to save the wrong one.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Wed Dec 17, 2014 7:43 am

I don't think this is the problem because it opens the file in the documents folder. Any ideas how I might check this?

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

Re: Saving a data stack in android

Post by jacque » Wed Dec 17, 2014 8:29 pm

keith.izatt wrote:I don't think this is the problem because it opens the file in the documents folder. Any ideas how I might check this?
You could insert a debugging line into the script just before you try to open the copy in the documents folder. This will give you a list of all currently open stacks: answer the mainstacks
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Fri Dec 19, 2014 7:59 am

when I run the script "answer the mainstacks" I get a message that I have the launchstack running and the appstack. Will this have some bearing on being able to save? Frustrated, this should be easy. Thank you for your continued help.

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

Re: Saving a data stack in android

Post by jacque » Fri Dec 19, 2014 8:40 pm

Looking at your script, I'm confused about what file you are copying. It looks like you are making a copy of the currently open appstack and saving it to the Documents folder. If so, then the copy has the same name as the original, even though their file paths are different. When you open the one in documents, the engine will see two stacks with the same name and will choose an arbitrary copy to save. If it chooses the original, the save will fail because that one resides in the standalone's (locked) engine folder.

But this is what confuses me:

Code: Select all

put the filename of this stack into masterfile -- what is "this stack"?
set the itemdelimiter to "/"
put "Appstack.livecode" into the last item of masterfile
What is "this stack"? If it's a separate stack you've loaded after the standalone starts up, you need to close the original before opening the copy or else rename the copy. There's an issue here in that a stack that is running a handler can't be closed and removed from memory until the handler finishes, which means you can't fully close the original from within its own openstack handler. However, you can rename the copy from there, so do that.

Code: Select all

on openstack
  set the defaultfolder to specialfolderpath ("Documents")
  put the filename of this stack into masterfile
  if there is not a file "Appstack.livecode" then
    set the itemdelimiter to "/"
    put "Appstack.livecode" into the last item of masterfile
    put specialFolderPath ("Documents") & "/AppStack.livecode" into appfile
    put URL ("binfile:" & masterfile) into URL ("binfile:" & appfile)
    set the name of stack appfile to "Copy of appfile" -- choose an appropriate name
  end if
  if the short name of stack masterfile is in the openstacks then close stack masterfile -- to be safe
  go stack specialFolderPath ("Documents") & "/AppStack.livecode"
  answer the filename of this stack--shows that it is in my documents folder
end openstack
If you want the copy to be named as the original is now, change the name of the original instead to something like "appstackTemplate". Then you can name the copy just "appstack". The above revision also checks to see if the original is open and closes it if it is, just as a precaution and because you don't need two copies open anyway. It won't fully close until the handler finishes, but it will no longer be open by the time you want to save the copy later on. I wrote the handler off the top of my head so test it in case.

A stack has three kinds of "names". It has a file name on disk (the path to the stack file,) a name (the short name) and a label (what the user sees in the title bar.) These can all be different, and the short name is always different from the filename. Referring to the stack by its filename will always identify the stack correctly; referring to the stack by the short name will cause problems if there are two same-named stacks open. The IDE protects you from opening two same-named stacks, but you need to manage that yourself in a standalone.

If my theory is correct (and all this may be a false lead) then you should be able to save appstack using its short name. However, it is also okay to refer to the stack by its filename if you want to be sure you are saving the correct copy:

Code: Select all

  save stack (specialFolderPath ("Documents") & "/AppStack.livecode")
But if the above works, you shouldn't need to use the filename after the setup is finished.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Sun Dec 21, 2014 7:56 pm

tried script and no luck. worked with it and still no luck. thanks for all your help.
Any known scripts that work for this?

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

Re: Saving a data stack in android

Post by jacque » Sun Dec 21, 2014 11:51 pm

This should work transparently, there must be something else going on. If your Save button is in the same appstack that you want to save, then try this in the button script:

Code: Select all

on mouseUp
  save this stack
end mouseUp
That should tell the engine to save the copy that is currently open.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keith.izatt
Posts: 14
Joined: Mon Dec 15, 2014 4:51 am

Re: Saving a data stack in android

Post by keith.izatt » Mon Dec 22, 2014 12:20 am

I disabled the code that takes me to the file in documents folder and put a button on the launchstack that reads

Code: Select all

on mouseUp
   set the defaultfolder to specialfolderpath("Documents")
   if there is not a file "appstack.livecode" then
      answer "no such file."
      end if 
end mouseUp
It answers "no such file" which leads me to believe there is no such file. Ideas?

Post Reply

Return to “Android Deployment”