Revision as of 11:37, 13 May 2009 by tapla (Talk | contribs)

Storing settings in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 3rd Edition, FP2, S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
Keywords: widget.setPreferenceForKey(), widget.preferenceForKey()
Created: (27 Jan 2009)
Last edited: tapla (13 May 2009)


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

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" />


// 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.");


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

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 for 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.
  • 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 unpatched stub applications, see Example stub.
178 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.