Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to listen for touches on the physical Android back button?

I couldn't find it in the docs, is there a module, or some other way to catch events from the android back button? If not it would be a nice and probably quick module to add.

like image 241
Sam Schooler Avatar asked Jun 18 '12 03:06

Sam Schooler


1 Answers

No: the back button just pops you one item back in the history stack. You do something like change the hash fragment to track navigation through your app (frameworks like Backbone.js can do this for you automatically).

The reason we've taken that approach is there's no hardware back button on iOS so we're wary of setting people up to rely on it in their app, only for the app to be fundamentally broken on that platform: we're aiming for consistency of completeness at the moment.

Update: due to popular demand, we've added support for controlling the back button behaviour on Android: http://docs.trigger.io/en/v1.4/modules/event.html#backpressed-addlistener - note backPressed.preventDefault too.

The event handler is passed a function which, when invoked, closes the app, so you could have code like:

forge.event.backPressed.addListener(function (close) {
  if (atHomeScreen) {
    close();
  }
}
like image 125
James Brady Avatar answered Oct 10 '22 09:10

James Brady