Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with data persistance please.

I have an app that the user will input text in the settings portion and the data is sent to the device via the companion. the resulting string would be like the example below.

{"data":{"key":"userName","newValue":"{\"name\":\"Joe User\"}"}}

 

I need to have these settings stay with the device when the phone is not around. I attempting to write these settings to a file that the app can then access for the data but I am having issues constructing what needs to happen.

I have been up and down the FS API and File System Guides trying different things and combed through the community forums with no luck.

 

Can someone give a better explaination on how to do this?

 

 

Best Answer
21 REPLIES 21

@jomis003

 

evt.data.key contains the settings name (settingsKey).

 

By using document.getElementById(evt.data.key) the code will get reference to the GUI element with an ID the same as that of the settings key.

 

By doing this, you are not needing to write lots of code to cross reference the settingsKey with the GUI element id.

 

Personally, I would avoid spaces in field names and most certainly id's. 

 

The onmessage event will fire once for each setting that is sent to the Ionic.

 

The onunload code will need to directly reference all of the settings you want to store in the file, as this event is only run once onunload.

 

To answer your question, the code has been written with assumption that settingsKey = GUI field ID, as per the notes above.

 

Try putting console.log(evt.data.key) into the onmessage event function to what happens when you run your application. It may help answer some of your questions.

Best Answer
0 Votes

Thanks! -  I think I am running myself in cirlcles with everything being label 1,2,3 etc. that I couldnt differintiate which one was which.

Best Answer
0 Votes