Search code examples
androidibm-mobilefirstworklight-runtime

Device Backs Button is closing Alert box in Worklight 6.2


When alert/confirm box is popped up on screen and I press device's back button, then the poped up alert/confirm box is getting close(without firing any event). How can I avoid this?

Below is the calling code:

**var buttons = [
                {
                    text : Messages.LBL_OK,
                    handler : doLogout
                }
              ];
showSuccess(Messages.ALERT_FILING_CONFIRMATION,buttons);**


function showSuccess(text,buttons){
    showDialog(Messages.LBL_CMN_DOALOG_SUCCESS_TITLE, text, buttons);
}

function showDialog(title,text,buttons){
    if(title == null || title == undefined){
        title = Messages.LBL_CMN_DOALOG_TITLE;
    }
    if(buttons == null || buttons == undefined){
        buttons = [
                       {
                        text : Messages.LBL_OK,
                        handler : defaultOK
                       }
                  ];
    }
    WL.SimpleDialog.show(title,text,buttons);
}

Solution

  • This is the expected behavior in Android.

    However, if you'd like to avoid this default behavior, you could use the WL.App.overrideBackButton API in key locations in your code so that the button will 'do nothing'. When you're done, you can then use WL.App.resetBackButton to reset the back button's behavior back to its default state.

    For example:

    WL.App.overrideBackButton(callback);
    
    function callback(){
     // doing nothing...
    }
    

    You could use the above before calling WL.SimpleDialog.show() and dismiss it in the dialog's button callback.