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

1

6

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.

Rancor answered 5/12, 2011 at 10:34 Comment(0)
D
9

You have to cancel the bubble of the event.

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

    Ti.App.fireEvent('android_back_button');
});
Departed answered 10/4, 2013 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.