Search code examples
androidangularjscordovahybrid-mobile-apponsen-ui

Onsen 1.3.14 android backbutton exit application instead of calling navi.popPage()


Im using Onsen 1.3.14. From what I've read, I thought android backbutton should be calling navi.popPage() by default, but instead my application always exited.

I also have tried using this

Workaround using $rootScope

but it still wont work.

Is it a bug? Is there a workaround to make android backbutton not exiting the app?

Thanks.

Regards


Solution

  • It's not true that the android backbutton should be calling navi.popPage(). What if, for example, there is a sliding menu instead of a navigator?

    If you want to implement a popPage, you can write something like this:

    document.addEventListener("backbutton",onBackButtonPressed, false);
    
    function onBackButtonPressed(){
            var element = document.querySelector("ons-navigator");
            element.popPage();
    }
    

    If you want to learn more about how to handle the android backbutton in Onsen UI, you can take a look at the official documentation:

    https://onsen.io/guide/overview.html#HandlingBackButton