Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:back (device back button) event in Titanium not working

Hi i am working on android application development.I am using Titanium studio for development. I create a simple application.I want to capture the device back button event in my application because I don't want to user android default tabs in titanium.I am creating my own tabs.I tried following code :

:list.js

var expt = Titanium.UI.currentWindow; 
expt.addEventListener('android:back', function (e) 
{
    Ti.App.fireEvent('expt_back_event');
});

:app.js

Ti.App.addEventListener('expt_back_event',function(e)
{
    alert('hiiii in side event listener');
});

But its not working instead of giving pop-up it closed my application which I don't want. Is there any way to obtain this result.

like image 742
nilkash Avatar asked Dec 05 '11 10:12

nilkash


1 Answers

You have to cancel the bubble of the event.

mainWindow.addEventListener('android:back', function(e) {
    e.cancelBubble = true;

    Ti.App.fireEvent('android_back_button');
});
like image 176
aferrandini Avatar answered Oct 17 '22 06:10

aferrandini