android:back event doesn't work
I'm trying to use an android:back event on a heavy-weight window (opened using modal:true) to close the window when the back button is pressed. However this event never fires, is this another bug, I copied the code exactly from Titanium's own example…
win.addEventListener('android:back', function (e) {
Ti.API.Info("Pressing Back Will Not Close The Activity/Window");
});
1 Answer
-
Accepted Answer
Hi Justin
You don't need to explicitly configure the back button; it's default function is to close modal views.
However, if you wish to execute other code and also close the modal view when the user presses the back button, you can do so as follows:
var win = Ti.UI.currentWindow; win.addEventListener('android:back', function (e) { Ti.API.Info("Pressing Back Will Not Close The Activity/Window"); win.close(); });
Note that you may need SDK 1.5.X rather than 1.4.X in order for this to work, which you can obtain from the Continuous Builds page.
Hope this helps