How to quit app on specific page


#1

Hello everybody :smile:

I have a little issues $ionicPlatform.onHardwareBackButton(); Indeed i don’t know how to use :s
i would like create a ionicpopup.confir for to quit app with back button is pressed on android. But i don’t see how to do.

i have that in my main controller but it’s doesn’t work :s

$ionicPlatform.onHardwareBackButton(function(){
    alert("back button press");
    $ionicPopup.confirm({
        title: 'Quit TechForum 2014 app',
        content: 'Do you want to close TechForum app ?'
    }).then(function(res) {
        if(res) {
            $ionicPlatform.exitApp();
        }
    });
});

First i have test with ionic.platform in my main JS " app.js" before var app = angular.module(‘app’); but i don’t call a ionic fonction. I want to quit app when user is on main page ( with ion-tab) not when is on other page :s


#2

Perhaps try injecting $state into your function and then checking the current state against the state you want to close on?


#3

Did you try changing $ionicPlatform.exitApp(); by ionic.Platform.exitApp();


#4

It’s does’nt work, when i tap on back button, i back on a previous page and after display a popup.
And when i click on " Cancel" and re-click on backbutton, a popup display two time, and tree time if i click 3 time on “cancel”


#5

In a angular.run doesn’t work. and how to blocked a back a page view when i click on a back button ?