(Difference between revisions)

Storing settings in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
croozeus (Talk | contribs)
m (Developing code snippet Storing settings in WRT moved to Storing settings in WRT: - More Suggestive & appropriate)
seppo_fn (Talk | contribs)
Line 3: Line 3:
|platform=S60 5th Edition
|platform=S60 3rd Edition, FP2, S60 5th Edition
|devices=Nokia 5800 XpressMusic
|devices=Nokia 5800 XpressMusic
|category=Web Runtime (WRT)
|category=Web Runtime (WRT)
Line 14: Line 14:
This code snippet shows how to use methods <tt>widget.setPreferenceForKey()</tt>
This code snippet shows how to use methods <tt>widget.setPreferenceForKey()</tt>
and <tt>widget.preferenceForKey()</tt> to save and then restore data for
and <tt>widget.preferenceForKey()</tt> to save persistent data and then restore it when restarting
the application.
the application.

Revision as of 15:48, 30 April 2009

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: setPreferenceForKey, preferenceForKey
Created: (27 Jan 2009)
Last edited: seppo_fn (30 Apr 2009)


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

Source file: StoreSettings.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="script/StoreSettings.js" />
<body onload="init( )">
<input id="txt" type="text"></input>
<input type='button' onclick='dochange( )' value='Save'/>

Source file: StoreSettings.js

* This function loads previously saved string and sets it to input field

function init( ) {
// Creating new menu item
var save = new MenuItem("Save", 12);
// Setting handlers for main menu items
save.onSelect = dochange;
// Adding items to menu
// Start displaying menu
// Checking existence of key and loadig string to input field if exists
document.getElementById( 'txt' ).value = widget.preferenceForKey( 'key' );
* Function saves string from input field to system

function dochange( ) {
widget.setPreferenceForKey( document.getElementById( 'txt' ).value, "key" );


Upon loading shows text input field. You can change text in this field and use "Save" button or menu command to save it. Saved text will be restored to text input field on next launch of the application.

Supplementary material

  • You can test the storing of setting in action in a simple, executable application into which this code snippet has been patched. The executables and source files are available for download at: Media:Storing_settings_in_WRT.zip.
  • You can examine all the changes that are required to implement the above mentioned features in an application. The changes are provided in unified diff and color-coded diff formats: link_to_patchs
183 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.