×
Namespaces

Variants
Actions
(Difference between revisions)

Storing state on exit in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix links)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Browsing]]
+
[[Category:Symbian Web Runtime]][[Category:JavaScript]][[Category:Code Examples]][[Category:Files/Data]]
[[Category:Technical Solution]]
+
{{ArticleMetaData <!-- v1.2 -->
[[Category:JavaScript]]
+
|sourcecode= [[Media:StoreStateOnExit.zip]]
[[Category:Widget]]
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
+
|devices= Nokia N97, Nokia N97 mini
__NOTOC__
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
__NOEDITSECTION__
+
{{KBTS}}
+
{{CodeSnippet
+
|id= TSC001536
+
 
|platform= S60 5th edition
 
|platform= S60 5th edition
|devices= Nokia N97, Nokia N97 mini
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|category= WRT
+
|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
 +
|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
 
|subcategory= JavaScript
|creationdate= December 23, 2009
+
|id= TSC001536
|keywords= widget.onexit
+
 
}}
 
}}
  
Line 27: 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 35: 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://library.forum.nokia.com/topic/Web_Developers_Library/GUID-DF4D8745-B6D4-4BC4-AF2D-0F71F28E9F27.html setPreferenceForKey] can be used.  At startup, the last stored state can be loaded using [http://library.forum.nokia.com/topic/Web_Developers_Library/GUID-E8E82EBC-05E6-49A2-9451-BF02986BCEE8.html 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].
 
<code javascript>
 
<code javascript>
 
  var lastActiveFSView;
 
  var lastActiveFSView;
Line 52: Line 61:
 
</code>
 
</code>
  
For a complete example, see: [http://wiki.forum.nokia.com/index.php/File:StoreStateOnExit.zip StoreStateOnExit.zip]
+
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.
51 page views in the last 30 days.