×
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 (Bot change of links to internal format.)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot fixing redirect link.(Moving links from forum.nokia.com TO developer.nokia.com))
Line 33: Line 33:
 
<tt>widget.onexit</tt> is fired every time a widget is closed, just before the last <tt>onhide</tt> event.  
 
<tt>widget.onexit</tt> is fired every time a widget is closed, just before the last <tt>onhide</tt> 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;

Revision as of 15:06, 21 June 2011

Template:KBTS

Article Metadata
Tested with
Devices(s): Nokia N97, Nokia N97 mini
Compatibility
Platform(s): S60 5th edition
Article
Keywords: widget.onexit
Created: (23 Dec 2009)
Last edited: hamishwillee (21 Jun 2011)

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.

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

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

×