Search code examples
androidcordovasplash-screen

Back button Launches Splash Screen


I am developing Phonegap 2.7.0 + Android Application.
Problem is when I am on index.html page of my application and I press back button of device it Launches Splash Screen and ReInitiate Application.


Solution

  • From the Phonegap side, you could attach a handler function to the backbutton, something like this:

    function exitApp() {
        console.log("Exiting app");
        navigator.app.exitApp();
    }
    
    function onPressBack(e) {
        e.preventDefault();
        navigator.notification.confirm("Are you sure you want to quit?", function(result){
            if(result == 2){
                exitApp();
            }
        }, 'Quit My App', 'Cancel,Ok');
    }
    
    function deviceready() {
        $(document).bind('backbutton', onPressBack);
    }
    $(document).bind('deviceready', deviceready);
    

    If you're using jQuery Mobile for paging, you can keep track of whether it's the first page being shown and therefore whether to show the exit dialog - see my answer to this question