×
Namespaces

Variants
Actions
(Difference between revisions)

Storing settings in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix links)
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Tidy wiki text)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 +
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]]
 +
{{Abstract|This code snippet demonstrates how to save persistent data and then restore it when restarting the application by using the methods {{Icode|widget.setPreferenceForKey()}} and {{Icode|widget.preferenceForKey()}}, respectively.}}
 +
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= [[Media:SavingPersistentData.diff.zip]] [[Media:Storing settings in WRT.zip]]
 
|sourcecode= [[Media:SavingPersistentData.diff.zip]] [[Media:Storing settings in WRT.zip]]
Line 21: Line 24:
 
|author= [[User:MiGryz]]
 
|author= [[User:MiGryz]]
 
<!-- The following are not in current metadata -->
 
<!-- The following are not in current metadata -->
|subcategory= Files/Data
 
 
|id= CS001409
 
|id= CS001409
 
}}
 
}}
 
==Overview==
 
 
This code snippet demonstrates how to save persistent data and then restore it when restarting the application by using the methods {{Icode|widget.setPreferenceForKey()}} and {{Icode|widget.preferenceForKey()}}, respectively.
 
  
 
==Source: Relevant HTML components==
 
==Source: Relevant HTML components==
Line 71: Line 69:
 
* You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in [[Media:SavingPersistentData.diff.zip]].
 
* You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in [[Media:SavingPersistentData.diff.zip]].
 
* For general information on applying the patch, see [[Using Diffs]].
 
* For general information on applying the patch, see [[Using Diffs]].
* For unpatched stub applications, see [[Example stub]].
+
* For unpatched stub applications, see [[Example app stubs with logging framework]].
 
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Files/Data]][[Category:Code Snippet]]
+

Latest revision as of 09:20, 5 October 2012

This code snippet demonstrates how to save persistent data and then restore it when restarting the application by using the methods widget.setPreferenceForKey() and widget.preferenceForKey(), respectively.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition FP2, S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
Article
Keywords: widget.setPreferenceForKey(), widget.preferenceForKey()
Created: MiGryz (26 Feb 2009)
Last edited: hamishwillee (05 Oct 2012)

Contents

[edit] Source: Relevant HTML components

<div id="bodyContent" class="bodyContent">
<label for="txt">Text:</label>
<input id="txt" type="text"></input>
<input type="button" onclick="saveString();" value="Save" />
</div>

[edit] Source

// Initializes the widget
function init() {
// ...
 
// Loads the saved string into the input field if the key exists
var savedString = widget.preferenceForKey("key");
if (savedString != null) {
document.getElementById("txt").value = savedString;
}
}
 
// Saves the string from the input field to persistent storage.
function saveString( ) {
widget.setPreferenceForKey(document.getElementById("txt").value, "key");
alert("String saved.");
}

[edit] Postconditions

Upon loading, text that corresponds to key in the persistent storage is displayed. You can change the text and use the Save button to save it. It will be restored the next time the widget is launched.

[edit] Supplementary material

This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful to developers. The version of the WRT stub application used as a template in this snippet is v1.1.

This page was last modified on 5 October 2012, at 09:20.
202 page views in the last 30 days.
×