Search code examples
formsnavigationcodenameone

How to disable back button for certain forms


I want to disable the "back" button on a specific form, but in other forms (views) continue working.


Solution

  • You should override the allowBackTo on the statemachine, this method should return true by default so you can keep going back to other forms but return false for those forms which you do not want to allow going back to, for example, if you want to keep going back to all of your forms with the exception of one called "SplashScreen" you should do the following:

     @Override
        protected boolean allowBackTo(String formName){
            if ("SplashScreen".equals(formName)){
                  return false;
                }
                return true;
    
        }