Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created May 31, 2011 15:42
Show Gist options
  • Select an option

  • Save jonalter/1000709 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1000709 to your computer and use it in GitHub Desktop.
Android detect app closed with home button
Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
url:'main.js'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
var win2 = Titanium.UI.createWindow({
title:'Tab 2',
url:'main2.js'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Tab 2',
window:win2
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.open();
count = 0;
Ti.App.addEventListener('pause', function(){
count-=1;
Ti.API.info('Pause Event '+count);
if(count<=0){
// whatever you put here will fire when the app closes
Ti.Android.currentActivity.finish();
}
});
Ti.App.addEventListener('resume', function(){
count+=1;
Ti.API.info('Resume Event '+count);
});
var win = Ti.UI.currentWindow;
win.backgroundColor = 'red';
Ti.Android.currentActivity.addEventListener('pause', function(e){
setTimeout(function(){Ti.App.fireEvent('pause');},500);
});
Ti.Android.currentActivity.addEventListener('resume', function(e){
Ti.App.fireEvent('resume');
});
var win = Ti.UI.currentWindow;
Ti.UI.currentWindow.backgroundColor = 'blue';
Ti.Android.currentActivity.addEventListener('pause', function(e){
setTimeout(function(){Ti.App.fireEvent('pause');},500);
});
Ti.Android.currentActivity.addEventListener('resume', function(e){
Ti.App.fireEvent('resume');
});
@bigbluespace

Copy link
Copy Markdown

This doesn't work

@hirenpatel20283

Copy link
Copy Markdown

this does not works

@hirenpatel20283

Copy link
Copy Markdown

Please give me some hint on this,I really need help on this.
In my app I want to display one screen with password protection,when app goes in background and again in foreground then this password screen comes in picture and when user enter right password he is on screen from where app goes in background.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment