Page 1 of 1
Saving data
Posted: Sun Mar 02, 2014 3:34 am
by ferhan24badshah
So I'm almost done with my app for an android platform. My app basically stores data day by day according to what the user inputs in the app. I just came to realize that when the phone is restarted, turned off, or the app is cleared from active apps.....all the data stored on the app is gone!! :/ Is there anyway to prevent this from happening?
Re: Saving data
Posted: Sun Mar 02, 2014 4:00 am
by Simon
Hi Ferhan,
Nope
You have to store the data somewhere;
Code: Select all
on mouseUp
put specialFolderPath("documents") & "/Data.dat" into tFile
if there is a file tFile then
put url ("file:" & tFile) into tData
answer tData --show the contents of the file
else
answer "No data file located" --First run
end if
end mouseUp
and reload it on startup.
Simon
Re: Saving data
Posted: Sun Mar 02, 2014 4:05 am
by ferhan24badshah
Simon wrote:Hi Ferhan,
Nope
You have to store the data somewhere;
Code: Select all
on mouseUp
put specialFolderPath("documents") & "/Data.dat" into tFile
if there is a file tFile then
put url ("file:" & tFile) into tData
answer tData --show the contents of the file
else
answer "No data file located" --First run
end if
end mouseUp
and reload it on startup.
Simon
Hey Simon,
yeah i figured....was hoping for a miracle haha..
hmm is it okay if you clarify the code you have written? I'm not too sure what's going on...what button is being pressed? and the content is a bit confusing...not quite sure what is happening. thank you
Re: Saving data
Posted: Sun Mar 02, 2014 4:15 am
by Simon
OK here it goes
put specialFolderPath("documents") & "/Data.dat" into tFile
This is where the files are stored on mobile, Data.dat is just a filename
if there is a file tFile then
put url ("file:" & tFile) into tData
Go get the file if it is there.
So you have a game with a high score
each time you score a point you add it to tData
Normally I'd say when you close the app write tData out to a file but for mobile I say just write it every time a score is made.
put tData into url("file:" & tFile) (tFile may be a global)
Do you see how it works now?
Simon
Edit oh... yes you'd look for the file on openCard or somewhere