NativeScript applications have thefollowing life cycle events.
//在start()之后调用,如果是点击back键,重新进入则会调用onLaunch(context),然后调用onResume()
//点击home键或者back键时调用
//当点击back键时,不调用onExit(),只有直接kill掉才会调用
To persist user-defined settings, you need to use the local-settings
module. The local-settings
module is a staticsingleton hash table that stores key-value pairs for the application.
The getter methods have two parameters: a key and an optional default valueto return if the specified key does not exist. The setter methods have tworequired parameters: a key and value.
var localSettings = require("local-settings");
// Event handler for Page "loaded" event attached in main-page.xml.
function pageLoaded(args) {
localSettings.setString("Name", "John Doe");
console.log(localSettings.getString("Name")); // Prints "John Doe".
localSettings.setBoolean("Married", false);
console.log(localSettings.getBoolean("Married")); // Prints false.
localSettings.setNumber("Age", 42);
console.log(localSettings.getNumber("Age")); // Prints 42.
console.log(localSettings.hasKey("Name")); // Prints true.
localSettings.remove("Name"); // Removes the Name entry.
console.log(localSettings.hasKey("Name")); // Prints false.
}
exports.pageLoaded = pageLoaded;