Skip to content

Instantly share code, notes, and snippets.

@kristjanmik
Last active July 25, 2016 14:58
Show Gist options
  • Save kristjanmik/aefc77b5b05e792ecdd2 to your computer and use it in GitHub Desktop.
Save kristjanmik/aefc77b5b05e792ecdd2 to your computer and use it in GitHub Desktop.
A proper way to handle pause and resume event in titanium for android
var win = Ti.UI.createWindow({});
win.addEventListener("open", function(e) {
win.activity.addEventListener("resume", function() {
Ti.App.fireEvent('resume')
});
//Notice the pause event
win.activity.addEventListener("pause", function() {
Ti.App.fireEvent('paused')
});
});
//Now works perfectly
Ti.App.addEventListener('resume',function(){
})
Ti.App.addEventListener('paused',function(){
})
@b-abctech
Copy link

this is really useful, thanks

@Heavyblade
Copy link

really helpful (Y)

@balanza
Copy link

balanza commented Mar 2, 2016

Hi, thanks for the snippet.
Let me just ask a question: what if I open a new window from win? In that case, the paused event would be raised, but it's not the case. How can I discern from this case and the proper one?

@lowb1rd
Copy link

lowb1rd commented Jun 21, 2016

Isn't that basically the same as the window's FOCUS and BLUR events?

@shivagunasehkaran
Copy link

Actually, I need this for pushnotification count updating thing for Background and Foreground Its works fine. Thanks :)

@arildojr
Copy link

https://github.com/benbahrenburg/benCoding.Android.Tools
isInForeground() method solved my problem.

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