Namespaces
Variants
Actions
Revision as of 10:29, 5 July 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Storing state on exit in Symbian Web Runtime

Jump to: navigation, search
Article Metadata

Code Example
Tested 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)

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

100 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved