Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Have 'back' go to previous window instead of close the application

I am having a similar problem as [this one] (http://developer.appcelerator.com/question/37081/stop-the-back-button-closing-app-on-android).

Basically, I want my 'back' button (in Android) to reopen the previously opened window, instead of closing the application. However, I also want to have OptionMenu displayed.

From the referenced question, I found that the back button only works that way for heavyweight windows.

I have read on heavyweight windows from [here] (http://developer.appcelerator.com/question/32471/noob—android-menu-does-not-work) and the API docs for Titanium.UI.Window, and I have tried those with my application.

Setting modal to true makes the 'back' button go to the previous window, but it does not display my OptionMenu. I am experimenting with other values for modal, navbarHidden, and fullscreen as well. So far, the result is that I have either the OptionMenu, 'back', or none at all, never both.

When I have 'navbarHidden: false' only, I will get only OptionMenu. When I have 'modal: true', the back button will go to the previous window, but there is no OptionMenu even when 'navbarHidden: false'.

Some code to illustrate my point:

var winA = Titanium.UI.createWindow({  
    title:'Window A',
    navbarHidden: false, // will show OptionMenu, but 'back' closes the app

var winB = Titanium.UI.createWindow({
    title: 'Window B',
    backgroundColor: '#fff',
    modal:true // 'back' goes to previous window but no OptionMenu

Can anyone shed a light on this?

Thanks in advance.

Note: I'm currently using SDK continuous-1.4.3.

— asked December 3rd 2010 by Tania Ang
  • android
  • back
  • navigation
  • optionmenu

5 Answers

  • Capture the back button press like this:

    winB.addEventListener('android:back', function(e) {
    Ti.API.info("Log: The Android back button was pressed - DO SOMETHING!!!!");
    // when overriding the back button, the default behavior
    // needs to be explicitly coded

    — answered July 20th 2012 by John Gould
  • Set the following property for the window that you are closing

    exitOnClose: false
    — answered February 20th 2014 by TY Koh
  • Tania

    Would you post the code you have written so far? I'm sure someone can work it out for you.


    — answered December 3rd 2010 by Paul Dowsett
    • Thanks. I updated my question with some code.

      — commented December 4th 2010 by Tania Ang
    • Someone has any progress with that?
      I've same issue! I've searched and read a lot, but it's still hard!

      — commented March 29th 2011 by Daniel Maceira
  • cool support model, god knows how you guys reached 300K dev…

    — answered June 26th 2012 by eran shlomo
  • Did you ever solve your problem? I have the same issue.


    — answered June 13th 2013 by Reine Cárdenas
    1 Comment
    • Did you see my answer above? If you add an event listener to the window to capture the android:back event, it won't close the application anymore and you can specify the functionality you want to fire.

      — commented June 13th 2013 by John Gould
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.