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',
backgroundColor:'#fff',
navbarHidden: false, // will show OptionMenu, but 'back' closes the app
});
var winB = Titanium.UI.createWindow({
title: 'Window B',
backgroundColor: '#fff',
navbarHidden:false,
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.
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
}); -
Set the following property for the window that you are closing
exitOnClose: false
-
Tania
Would you post the code you have written so far? I'm sure someone can work it out for you.
Cheers
-
cool support model, god knows how you guys reached 300K dev…
-
Did you ever solve your problem? I have the same issue.
Thanks.