Saving data on mobile

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Saving data on mobile

Post by glenn9 » Wed Mar 17, 2021 9:39 pm

On deploying an app to mobile, I provide its data by including a data text file through 'Copy Files' in the standalone settings.

temp.png

I then import the data into the app using the following code:

Code: Select all

...
on openstack
set the defaultfolder to specialfolderpath("resources")
put url ("binfile:ArrayData.txt") into theEncodedArray
put arrayDecode(theEncodedArray) into vText

put specialfolderpath("documents") & "/" & "ArrayData.txt" into tMyPath
put arrayEncode(vText) into url ("binfile:" & tMyPath)
...
This works fine on mobile, and if the user then subsequently adds data, this is then saved as expected in specialfolderpath("documents").

However, if the app is closed and then restarted, the previously saved data is then, I think, overwritten by the original file from the specialfolderpath("resources").

I guess what I am trying to achieve is that on app installation on the mobile device, the data from specialfolderpath("resources") is transferred once to the app and then if the app is closed and opened again, it then only takes its data from specialfolderpath("documents").

I'm not sure how to achieve this, grateful for any help or suggestions etc.

Many thanks,

Glenn

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

Re: Saving data on mobile

Post by Klaus » Wed Mar 17, 2021 9:50 pm

Hi Glenn,

just check if the file is already in DOCUMENTS!

Code: Select all

on openstack
   put specialfolderpath("documents") & "/" & "ArrayData.txt" into tUserData
   put specialfolderpath("resources") & "/" & "ArrayData.txt" into tResData
   
   ## No file yet, so copy the resource file to folder DOCUMENTS
   if there is NOT a file tUserData then
      put url ("binfile:" & tResData) into url("binfile:" & tUserData)
   end if
   
   ## Now load the data from the DOCS folder
   put url ("binfile:" & tUserData) into theEncodedArray   
   ...
Best

Klaus

stam
Posts: 2680
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Saving data on mobile

Post by stam » Wed Mar 17, 2021 9:52 pm

Hi Glenn,
it probably is as simple as checking if specialfolderpath("documents") & "/" & "ArrayData.txt" exists

and only doing put arrayEncode(vText) into url ("binfile:" & tMyPath) if it doesn't?


--------------------------------
EDIT
--------------------------------
dammit!
outklaussed again lol

glenn9
Posts: 223
Joined: Wed Jan 15, 2020 10:45 pm
Location: Europe

Re: Saving data on mobile

Post by glenn9 » Wed Mar 17, 2021 9:57 pm

Klaus, Stam,

brilliant, thank you, that's solved it!

Another learning point...!

Regards,

Glenn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”