Search code examples
androidibm-mobilefirstworklight-studio

IBM Worklight - client-side API "overrideBackButton" doesn't work the second time


I want to make something happen when back button is pressed so I put this code in my app's .js file:

function wlCommonInit(){            
    // Common initialization code goes here
    WL.App.overrideBackButton(backFunc);
}

function backFunc(){
    alert('You will back to previous page');
}

After building and deploying the application and running it in a device, the alert is shown when I press the Back button.

If I now exit the app by pressing on the Home button and kill the app's process, and then open the app again and press the Back button - it doesn't work.


Solution

  • Place your code INSIDE wlCommonInit(). I suggest to do so in this manner:

    function wlCommonInit() {
        WL.App.overrideBackButton(backFunc);      
    }
    
    function backFunc() {
        alert('You will back to previous page');
    }
    

    Edit: Question updated with the above code snippet and new information based on the comments. Scenario works fine. See comments.