Created
September 13, 2011 16:57
-
-
Save jonalter/1214305 to your computer and use it in GitHub Desktop.
Android: back button finish activities and exit app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Titanium.UI.setBackgroundColor('#000'); | |
| var windows = []; | |
| // | |
| // create base UI tab and root window | |
| // | |
| var win1 = Titanium.UI.createWindow({ | |
| title : 'Tab 1', | |
| backgroundColor : '#fff', | |
| exitOnClose : true | |
| }); | |
| var but1 = Titanium.UI.createButton({ | |
| color : '#999', | |
| title : 'Open me', | |
| font : { | |
| fontSize : 20, | |
| fontFamily : 'Helvetica Neue' | |
| }, | |
| textAlign : 'center', | |
| width : 'auto' | |
| }); | |
| var but4 = Titanium.UI.createButton({ | |
| color : '#999', | |
| title : 'LogOut', | |
| font : { | |
| fontSize : 20, | |
| fontFamily : 'Helvetica Neue' | |
| }, | |
| textAlign : 'center', | |
| width : 'auto' | |
| }); | |
| var win3 = Titanium.UI.createWindow({ | |
| title : 'Win3', | |
| backgroundColor : '#fff', | |
| exitOnClose : false, | |
| navBarHidden : false | |
| }); | |
| var win4 = Titanium.UI.createWindow({ | |
| title : 'Win3', | |
| backgroundColor : '#fff', | |
| exitOnClose : false, | |
| navBarHidden : false | |
| }); | |
| var but2 = Titanium.UI.createButton({ | |
| color : '#999', | |
| title : 'Close me', | |
| font : { | |
| fontSize : 20, | |
| fontFamily : 'Helvetica Neue' | |
| }, | |
| textAlign : 'center', | |
| width : 'auto' | |
| }); | |
| win1.add(but1); | |
| win3.add(but2); | |
| win4.add(but4); | |
| but1.addEventListener("click", function(e) { | |
| windows.push(win3); | |
| win3.open(); | |
| }); | |
| but2.addEventListener("click", function(e) { | |
| windows.push(win4); | |
| win4.open(); | |
| }); | |
| but4.addEventListener("click", function(e) { | |
| //win4.open(); | |
| var win5 = Titanium.UI.createWindow({ | |
| title : 'Tab 1', | |
| backgroundColor : '#fff', | |
| fullscreen : true, | |
| exitOnClose : true | |
| }); | |
| windows.push(win5); | |
| win5.open(); | |
| win5.addEventListener('android:back', function() { | |
| Ti.API.info('back!'); | |
| var length = windows.length; | |
| for(var i = 0; i < length; i++) { | |
| windows[i].activity.finish(); | |
| } | |
| }); | |
| }); | |
| windows.push(win1); | |
| win1.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment