Search code examples
androidappceleratorappcelerator-alloy

Back press event of titanium


I am trying to handle the back press event of android in titanium using appcelerator. But when user presses back the app gets closed in android. Can any one tell me the solution.

exitOnClose= false ;

 $.index.addEventListener('androidback', function(e){
    // write your code here
    Ti.API.info('android back pressed');
    return;
});

I have added this code as per the suggestions but its not working.


Solution

  • Capture the event and do nothing

    Ti.UI.currentWindow.addEventListener('androidback',function(event){
          event.cancelBubble = true;
          return false;
    }
    

    Also use the exitOnClose property: http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-property-exitOnClose