android:back (device back button) event in Titaniu

2019-03-21 00:37发布

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.

1条回答
▲ chillily
2楼-- · 2019-03-21 01:15

You have to cancel the bubble of the event.

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

    Ti.App.fireEvent('android_back_button');
});
查看更多
登录 后发表回答