×
Namespaces

Variants
Actions
(Difference between revisions)

Storing state on exit in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot fixing redirect link.(Moving links from forum.nokia.com TO developer.nokia.com))
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix links)
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
[[Category:Browser]][[Category:Symbian Web Runtime]]
+
[[Category:Symbian Web Runtime]][[Category:JavaScript]][[Category:Code Examples]][[Category:Files/Data]]
__NOTOC__
+
{{ArticleMetaData <!-- v1.2 -->
__NOEDITSECTION__
+
|sourcecode= [[Media:StoreStateOnExit.zip]]
{{KBTS}}
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
{{CodeSnippet
+
|id= TSC001536
+
|platform= S60 5th edition
+
 
|devices= Nokia N97, Nokia N97 mini
 
|devices= Nokia N97, Nokia N97 mini
|category= WRT
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory= JavaScript
+
|platform= S60 5th edition
|creationdate= December 23, 2009
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|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.onexit
 
|keywords= widget.onexit
 +
|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= 20091223
 +
|author= [[User:Kbwiki]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= JavaScript
 +
|id= TSC001536
 
}}
 
}}
  
Line 23: Line 36:
 
*store the state on exit and load state information when the widget is started.
 
*store the state on exit and load state information when the widget is started.
  
The closing of a widget can be detected by defining an event handler for the <tt>widget.onexit</tt> event.  
+
The closing of a widget can be detected by defining an event handler for the {{Icode|widget.onexit}} event.  
  
 
<code javascript>
 
<code javascript>
Line 31: Line 44:
 
</code>
 
</code>
  
<tt>widget.onexit</tt> is fired every time a widget is closed, just before the last <tt>onhide</tt> event.  
+
{{Icode|widget.onexit}} is fired every time a widget is closed, just before the last {{Icode|onhide}} event.  
  
 
For storing the state, [http://www.developer.nokia.com/Resources/Library/Web/ setPreferenceForKey] can be used.  At startup, the last stored state can be loaded using [http://www.developer.nokia.com/Resources/Library/Web/ preferenceForKey].
 
For storing the state, [http://www.developer.nokia.com/Resources/Library/Web/ setPreferenceForKey] can be used.  At startup, the last stored state can be loaded using [http://www.developer.nokia.com/Resources/Library/Web/ preferenceForKey].
Line 48: Line 61:
 
</code>
 
</code>
  
For a complete example, see: [[:File:StoreStateOnExit.zip|StoreStateOnExit.zip]][[Category:Technical Solution]][[Category:JavaScript]]
+
For a complete example, see: [[:File:StoreStateOnExit.zip|StoreStateOnExit.zip]]

Latest revision as of 10:29, 5 July 2012

Article Metadata
Code ExampleTested with
Devices(s): Nokia N97, Nokia N97 mini
Compatibility
Platform(s): S60 5th edition
Article
Keywords: widget.onexit
Created: User:Kbwiki (23 Dec 2009)
Last edited: hamishwillee (05 Jul 2012)

[edit] Overview

In some situations, it might be necessary to store the widget state on exit. One of these use cases is storing the last shown full screen view before the widget is minimised to the home screen by pressing the Exit key. The same view can then be shown to the user the next time the widget is maximised.

[edit] Solution

To implement this you will need to:

  • detect when the widget has been closed
  • store the state on exit and load state information when the widget is started.

The closing of a widget can be detected by defining an event handler for the widget.onexit event.

 widget.onexit = function() {
// store current view
}

widget.onexit is fired every time a widget is closed, just before the last onhide event.

For storing the state, setPreferenceForKey can be used. At startup, the last stored state can be loaded using preferenceForKey.

 var lastActiveFSView;
 
widget.onexit = function() {
if (lastActiveFSView) {
widget.setPreferenceForKey(lastActiveFSView, "lastActiveFSView");
}
}
 
window.onload = function() {
lastActiveFSView = widget.preferenceForKey("lastActiveFSView");
}

For a complete example, see: StoreStateOnExit.zip

This page was last modified on 5 July 2012, at 10:29.
62 page views in the last 30 days.