×
Namespaces

Variants
Actions
(Difference between revisions)

Storing settings in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
copyeditor (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Tidy wiki text)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]]
__NOEDITSECTION__
+
{{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.}}
{{KBCS}}
+
 
{{CodeSnippet
+
{{ArticleMetaData <!-- v1.2 -->
|id=CS001374
+
|sourcecode= [[Media:SavingPersistentData.diff.zip]] [[Media:Storing settings in WRT.zip]]
|platform=S60 3rd Edition FP2, S60 5th Edition
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices=Nokia 5800 XpressMusic
+
|devices= Nokia 5800 XpressMusic
|category=Web Runtime (WRT)
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory=Files/Data
+
|platform= S60 3rd Edition FP2, S60 5th Edition
|creationdate=June 9, 2009
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|keywords=widget.setPreferenceForKey(), widget.preferenceForKey()
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= widget.setPreferenceForKey(), widget.preferenceForKey()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090226
 +
|author= [[User:MiGryz]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001409
 
}}
 
}}
 
==Overview==
 
 
This code snippet demonstrates how to save persistent data and then restore it when restarting the application by using the methods <tt>widget.setPreferenceForKey()</tt> and <tt>widget.preferenceForKey()</tt>, respectively.
 
  
 
==Source: Relevant HTML components==
 
==Source: Relevant HTML components==
Line 49: Line 60:
 
==Postconditions==
 
==Postconditions==
  
Upon loading, text that corresponds to <tt>key</tt> in the persistent storage is displayed. You can change the text and use the <tt>Save</tt> button to save it. It will be restored the next time the widget is launched.
+
Upon loading, text that corresponds to {{Icode|key}} in the persistent storage is displayed. You can change the text and use the {{Icode|Save}} button to save it. It will be restored the next time the widget is launched.
  
 
==Supplementary material==
 
==Supplementary material==
Line 55: Line 66:
 
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 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.
  
* The patched, executable application that can be used to test the features described in this snippet is available for download at [[Media:Storing_settings_in_WRT.zip]].  
+
* The patched, executable application that can be used to test the features described in this snippet is available for download at [[Media:Storing settings in WRT.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]].
 
* 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:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Files/Data]]
+

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.
177 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×