kalpit yadav
kalpit yadav

Reputation: 1

Android back button not working with hybrid app ~ using onsen ui (angular js) building app using crosswalk

When I build the hybrid app using crosswalk - android Back button is not working with onsen ui framework(using angular js).

Below is the code which i have used...

document.addEventListener("backbutton", onBackKeyDown, false); 

function onBackKeyDown() {
    // Handle the back button
    alert("Backbutton is pressed!");
    var element = document.querySelector(".navigator-container");
    var scope = angular.element(element).scope();
    scope.popPage();
}

Upvotes: 0

Views: 628

Answers (1)

Ilia Yatchev
Ilia Yatchev

Reputation: 1262

As @kabaehr mentioned you may need to wait for everything to be ready first. That means either of the following:

document.addEventListener('deviceready', function(){ ... });

ons.ready(function(){ ... });

The other thing which may be specific to Onsen UI is the fact that it's already doing some handling of that event, so you could try to use the API which is given for that.

Here are the docs for that API. Currently it seems like the method which you want is:

ons.setDefaultDeviceBackButtonListener(onBackKeyDown)

Although that method doesn't sound too nice so maybe the name will change in the future.

For now feel free to try if any of these options seem to work for you.

Upvotes: 1

Related Questions