console.info("Failed to get the value of 'startup'. Cause: "+err);
})
}).catch((err)=>{
console.info("Failed to get the preferences.")
});
console.info("Failed to get the value of 'startup'. Cause: "+err);
})
```
5. Store data persistently.
Use the **flush()** method to flush data from the **Preferences** instance to its file.
...
...
@@ -161,11 +167,12 @@ Use the following APIs to delete a **Preferences** instance or data file.
Specify an observer as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and saved by **flush()**, the observer callback will be invoked to return the new data.
```js
varobserver=function(key){
letobserver=function(key){
console.info("The key"+key+" changed.");
}
preferences.on('change',observer);
preferences.put('startup','auto',function(err){
// The data is changed from 'auto' to 'manual'.
preferences.put('startup','manual',function(err){
if(err){
console.info("Failed to put the value of 'startup'. Cause: "+err);