- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Testing Android app with App Preview on Galaxy S5 Android version 5.0. Also debugging via USB debugging through Chrome. Intel XDK version 2673. Tried using Cordova version 4.1.2 and 5.1.1. Tried with and without the Cordova device plugin.
Couldn't capture the back button event on my main project, so I made a side simple HTML5 + Cordova project and copied in the back button event template from the Cordova docs, and the onLoad and DeviceReady functions both fire, but the backbutton event is never captured - just like on my main project. Any help would be appreciated:
<!DOCTYPE html>
<html>
<head>
<title>Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
alert("HI");
}
</script>
</head>
<body onload="onLoad()">
back doesn't work
</body>
</html>
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In order to capture the pressing of the back button on your Android device, you are required to add the following code:
document.addEventListener("backbutton", yourCallbackFunction, false); function yourCallbackFunction() { //Handle the back button }
The above event handler is supported on Android. For more information in regards to this and other Cordova lifecycle events, visit https://cordova.apache.org/docs/en/4.0.0/cordova/events/events.html for Cordova 4 and https://cordova.apache.org/docs/en/latest/cordova/events/events.html for Cordova 5.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That is literally the code I posted above, saying it is not working. And you link me to the page where I said I got the code from. Can you try to provide some reason as to why my code may not be working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think there's a bug in App Preview that prevents you from seeing that backbutton event. Try a building a simple app and testing it in a built app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Paul you are correct. We released a beta of our app to the store for testing, downloaded it through there and the back button trigger worked properly.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page