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

牧云@^-^@ 提交于 2020-01-01 03:16:09

问题


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:


You have to cancel the bubble of the event.

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

    Ti.App.fireEvent('android_back_button');
});


来源:https://stackoverflow.com/questions/8383992/androidback-device-back-button-event-in-titanium-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!