Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


As a WebWorks developer, I would like to listen for an "onexit" or "onclose" event. #191

RonMen opened this Issue · 10 comments

5 participants


Since a WebWorks developer can programmatically close an app with the call would it be possible to listen for when the app get closed to do something before closing the app?

The can be handled from an apps menu to do something before exiting the app, but if the user minimizes and closes the app, IMHO, we should also be able to do something "onbeforeexit" to eg. don't lose data.


the problem with this event is reliability, you will get the event no problem, in fact you can easily do it but its not a sync API which means that your webview will already be closed before you can really do something useful.
I can tell you how to hook up the event if you want to try it yourself.


Would be nice if you can point me to something to give it a try. I think it is essential to have something like onbeforeexit to be able to handle things.


In your downloaded build go to /Framework/lib/framework.js

In the registerApplicationEvents add an event listener for onExit

function registerApplicationEvents() {
    if ( && {
        chrome.internal.application = {};
        chrome.internal.application.onWindowState = function (state) {};
        chrome.internal.application.onSwipeDown = function () {
            if (onSwipeDown) {
        chrome.internal.application.onWindowActive = function () {
            if (onResume) {
        chrome.internal.application.onWindowInactive = function () {
            if (onPause) {
        //just added
        chrome.internal.application.onExit = function () {
            if (onExit) {

Add an onExit var /Framework/lib/framework.js and also add add a setter

 onSwipeDown = null,
    onPause = null,
    onResume = null,
    onExit = null;

setOnExit: function (handler) {
        onExit = handler;

Go to / Framework / ext / / navEvents.js

In the addEventListener
add another case for the onExit

 case "onExit":

In the / Framework / ext / / index.js

In the _actionMap add another item for exit
 exit: {
            context: require("./navEvents"),
            event: "exit",
            trigger: function () {

now you should be to call blackberry.addEventListener("exit",...) from your client code.


THX for adding source here. Added it line by line to my SDK but it doesn't work for me. The only one thing I changed is when registering the event handler, I used blackberry.event.addEventListener("exit", function(evt) {console.log(evt);}, false); instead of yours blackberry.addEventListener("exit",...) without the event in there.

BTW: I revisited my .bar file and all the things done are in there!


yes yours is correct and you don't need the third parameter. So its suppose to work like this -
blackberry.event.addEventListener("exit", function () {});
You can put a console.log here and see whether it gets called on the framework or not?

    chrome.internal.application.onExit = function () {
        if (onExit) {

Now carefully have webinspector open and see whether you get the console.log or not.


Hey guys, where do we stand with this?


Hi. @nukulb mentioned that the webview of an app already will be closed before something happend this isn't a good usecase for an onexit event handler/listener, isn't it? All that I wanted to be aware of is to make sure that the state of the data used in an app can be stored to LocalStorage/DB before the app gets closed. From inside I'm able to handle it with the but this happens before the webview is really closed. If the user minimizes app to background and swipes it to close nothing can be done here and that can't be a solution I think.


Any update on this?


I looked into this a few months ago, but I could not get an event into the client web view before it got terminated.

The conclusion was that this is not possible without making changes on device.



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.