Hi Dinde,
Thank you for trying Crosswalk!
Robert is right, basically we need to override onBackPressed() in Java code, in
Cordova or Crosswalk extensions. Currently the easiest way is using Cordova.
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
// Handle the back button
}
But if you don’t like it, I tried window.onbeforeunload at first, it works for
browsers but failed for Crosswalk app. Luckily, the “Back Button Detection
Object V 1.0.1” (by Brooke Bryan) helps.
<script src="http://www.bajb.net/code/backbutton/backfix.min.js"></script>
<script>
bajb_backdetect.OnBack = function()
{
alert('You clicked it!');
}
</script>
I tried it works on pure Crosswalk beta build crosswalk-14.43.343.4 with
hardware back key device, please make sure if it works on software back key
devices work in case any compatibility issues, the back logic/process need to
be think more.
Brooke Bryan
August 30, 2012
You are free to use the code wherever you like
Hope it helps, seems like the jQueryMobile tried to use this to detect if the
user clicked on the back arrow on an iOS or Android device in comments [2].
[1] http://www.bajb.net/2010/02/browser-back-button-detection/
BR
Belem
From: Crosswalk-help
[mailto:[email protected]] On Behalf Of Dinde
Games
Sent: Monday, May 18, 2015 8:41 PM
To: Robert Norris
Cc: [email protected]
Subject: Re: [Crosswalk-help] How to handle the back button on the device ?
Thank you for your answer Robert.
The thing is I don't develop in Java, my game is a full javascript application,
so I don't have the possibility to change the activity directly. That's why I
wanted to know if there is a way (like a bridge) to do it in javascript. For
example I know you can do it with cordova, but I'd like to avoid it if it's
possible.
2015-05-18 12:21 GMT+02:00 Robert Norris
<[email protected]<mailto:[email protected]>>:
This is an Android function, nothing to do with Crosswalk. Override
onBackPressed() in your activity. See
http://developer.android.com/reference/android/app/Activity.html#onBackPressed%28%29.
Rob N.
On Mon, 18 May 2015, at 08:13 PM, Dinde Games wrote:
Hello,
I'm a beginner with crosswalk, and I'm using it to make a game (with Phaser for
those who know).
So, I use crosswalk (with the CLI, not with intel XDK) as my wrapper, and I'd
like to know how can I handle the back button on the android device ? At the
moment it quits the game withtout any warning, I'd like to prevent that because
the user could hit that accidentally, so I would like to write my custom
function in javascript but I don't know if there is a javascript event
available?
After some researches, I saw several answers about crosswalk with cordova, but
I'm not using cordova, and I hope I won't have to, because I don't really need
it and I try to have light apk in the end, and I don't know if it will affects
the performances of my game.
Thanks in advance !
_______________________________________________
Crosswalk-help mailing list
[email protected]<mailto:[email protected]>
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help
_______________________________________________
Crosswalk-help mailing list
[email protected]<mailto:[email protected]>
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help
_______________________________________________
Crosswalk-help mailing list
[email protected]
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help