Voting: 
Vote up!
0 Votes
1 Replies

Saving data will persist after App re- installment

Question asked by Nivrita Parai on Nov 23, 2015 05:05 EST

Hi, In our application there is a requirement, where we need to store a Flag. So, that if the Flag is true, we have to call some events otherwise we will call some other events. But we have to keep the status Flag even if a particular user will re-install the same App. Currently we are using kony.ds.save() to Store the Flag status. But the same is getting removed after re-intalling the App. Is there any way-out in Kony to hold/keep the Flag value even after re-installing the App. So that after re-installing the App, we can call the corresponding event based on the saved Flag value.   Please provide a solution.   Thanks in advance.

Vote up!
0 votes
Vote down!

Hi Nivrita,

Thank you for contacting community forums.

We can achieve this by using File Api's.Please find below Sample code .

For reading from the file and writting in the file:

Code:

var mainLoc = kony.io.FileSystem.getDataDirectoryPath();

var fileLoc = mainLoc + constants.FILE_PATH_SEPARATOR + "myFile.txt";

try{

var ifFileExists = kony.io.File(fileLoc).exists();

if(ifFileExists) {

var reading = new kony.io.File(myFileLoc).read();

kony.print(JSON.stringify(reading));

if((reading.readAsText()) == "How are you?"){

                alert("writing was successful");

}

}else{

var myFile = new kony.io.File(fileLoc).createFile();

var writing = new kony.io.File(myFileLoc).write("How are you?");

}

Thanks.

Replied by: Dec 04, 2015 07:04 EST