Side Menu BackButton


#1

Hi, I have a problem using SideMenu when I navigate the view (using href = “# / app / templaten” and pressed the physical button again (Android) I navigate back obviously in history mode. What I want to do is to by pressing the physical button back, I exit the application. Anyone have any idea?
Thanks :smile:


#2

Can you provide a sample app of what you have?


#3

Try using registerBackButtonAction as suggested at registerBackButtonAction and then call ionic.Platform.exitApp() or navigator.app.exitApp() if the current state is your view’s state.

I haven’t tried this that but will have to soon so be interested to see if it works.


#4

As a follow up verified this works for me:

.run(function($ionicPlatform, $rootScope, $state) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }

        // Override the android back button
        $ionicPlatform.registerBackButtonAction(function () {

            if ($state.current.name === "app.home") {
                ionic.Platform.exitApp();
            }
            else if($state.current.name === "app.assessments") {
                $state.go("app.home");
            }
            else {
                navigator.app.backHistory();
            }

        }, 100);


    });
})

#5

Hi, thanks for sharing your code. I tried it and did not worked. as I spend with thousands of codes that probe. I found the problem was a problem of platform when executing that sentence gave me error compiling worked OK but not the Cordova. then I realized my stupid mistake app take Exit function of your code, ignoring the conditional IF, and then will incorporate a popup. thank you very much.