×
Namespaces

Variants
Actions
(Difference between revisions)

Storing settings in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
seppo_fn (Talk | contribs)
seppo_fn (Talk | contribs)
Line 87: Line 87:
 
* 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]]
 
* 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]]
  
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]
+
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 3rd Edition, FP2]][[Category:S60 5th Edition]]

Revision as of 15:51, 30 April 2009


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


Overview

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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="script/StoreSettings.js" />
<title>StoreSettings</title>
</head>
<body onload="init( )">
<div>
<input id="txt" type="text"></input>
<input type='button' onclick='dochange( )' value='Save'/>
</div>
</body>
</html>

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
menu.append(save);
 
// Start displaying menu
menu.showSoftkeys();
 
// Checking existence of key and loadig string to input field if exists
if(widget.preferenceForKey('key'))
{
document.getElementById( 'txt' ).value = widget.preferenceForKey( 'key' );
}
}
 
/**
* Function saves string from input field to system
*/

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


Postconditions

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
152 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.

×