- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
when I hit the back button on the phone the application is closed and, when reactivated, it starts from the beginning.
I tried to capture the event in these two ways, that work well within the emulator. Do not go instead in the final build on phone.
//First try document.addEventListener("backbutton", backButtonPressed, false); function backButtonPressed() { } //Second try document.addEventListener("intel.xdk.device.ready",function() { intel.xdk.device.addVirtualPage(); },false); document.addEventListener("intel.xdk.device.hardware.back", function() { intel.xdk.device.addVirtualPage(); }, false);
It needs some plugins for the event, to make it work with Ionic?
thank you
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the Cordova backbutton event capture you do not need to provide any special plugins. To use that older intel.xdk event capture, you'll have to include the intel.xdk.device plugin.
I recommend you use the Cordova API. See this Stack Overflow post for some examples: http://stackoverflow.com/questions/22609411/over-ride-the-back-button-of-android-device-through-phonegap-in-javascript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm using Ionic too and have the same problem: the app closes anyway. I'm using event.preventDefault() and
document.addEventListener("backbutton", onBackKeyDown, false);
Even though the code works and onBackKeyDown is called.
Is there any other way to prevent its default behaviour?
Ok, found this link in another topic http://www.gajotres.net/ionic-framework-handling-android-back-button-like-a-pro/ Gonna leave it here in case someone finds this topic first like I did :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posting this as an update to trying out what was posted in the link. Here is an error I get if I use
$ionicPlatform.registerBackButtonAction(function(event) {
$ionicPlatform is not defined
and the other one is if I change it with ionic.Platform.
ionic.Platform.registerBackButtonAction is not a function
So I'm back to being stuck again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Mario>
For me, it works good. I have:
document.addEventListener("backbutton", funNaoFazNada, false);
function funNaoFazNada() { }
Just it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anya-
If I understand correctly
- registering a backbutton event handler worked
- the backbutton event handler is called
- the app exits after the backbutton event handler is called
Are you using Crosswalk with your app?
Are you testing this using App Preview or have you built your app and installed it on a device?
Update:
Sorry I did not read more carefully; I did not realize you were using Ionic.
I see that you must have found this topic, where Paul pointed to this blog post.
If $ionicPlatform is undefined, there must be something wrong with how Ionic is configured or your code is being called before Ionic is initialized.

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