IOS Android back button

You must Login before you can answer or comment on any questions.

I'm looking for a recommendation on the best way to create a back button that would work on both IOS and Android. Would it be to simply create a Ti.UI.createButton() that links to the previous back?

1 Answer

here is an example of how to create the android back button using the Native back button.

Titanium.UI.setBackgroundColor('white');
 
var window1 = Ti.UI.createWindow({
  backgroundColor:"red",
  navBarHidden:false,
  title:"Main Window"
});
 
window1.addEventListener('click', function(){
 
  var window2 = Ti.UI.createWindow({
    backgroundColor:"green",
    navBarHidden:false,
    title:"Sub Window"
  });
 
  window2.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
 //   (in most cases, close) needs to be explicitly coded 
    window2.close();
  });
 
  window2.open();
 
});
 
window1.open();
you would basically add that event and either the name of the window to close or
Ti.UI.currentWindow.close();

— answered 10 months ago by Luis Martinez
answer permalink
2 Comments
  • I'm looking for something a bit more generic that would work on both Andoid and IOS. I know Titanium has Ti.UI.iPhone.createNavigationGroup() for IOS which implements a back button but is there anyway to combine this and the standard Android back button you mentioned together so that there is one code that handles back?

    — commented 10 months ago by Nando Cammarota

  • for IOS your going to need a button just because you know the home button means home, not back.

    — commented 10 months ago by Luis Martinez

Your Answer

Think you can help? Login to answer this question!