In many cases you need to store user specific data like app settings on the users device.
DroidScript provides some functions which makes it easier to handle this.
Some settings are just meaningful in a current running program.
For example if you keep track of the current app state (opened tabs, documents, pages).
For this purpose you can use the app.SetData and the app.GetData method.
To clear stored data use app.ClearData.
Many apps support in-app settings which will be loaded after each app start. The app object has several methods to save and load different types of data.
To clear a saved value use the app.ClearValue method.
Type | Save | Load |
---|---|---|
Boolean | SaveBoolean | LoadBoolean |
Number | SaveNumber | LoadNumber |
String | SaveText | LoadText |
JSON (any) | SaveJson | LoadJson |
If you have many properties to save you can use an object structure instead of saving each value on their own.
Load settings: var conf = JSON.parse( app.LoadText( "settings", "{}" ));
Save settings: app.SaveText( "settings", JSON.stringify( conf ));
Using Databases is the most elaborate variant of the three.
Using JSON objects is more practicable and performant in most cases.
DroidScript provides an extra OpenDatabase component for databases which uses the SQLitePlugin cordova-sqlite-storage.
For a demo Have a look at the Database example.