-
-
Save balanza/5fbd1253b65c36eb2e42 to your computer and use it in GitHub Desktop.
A proper way to handle pause and resume event in titanium for android
This file contains 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
/** | |
* A little workaround to proper handle resume and paused events on Android | |
*/ | |
var platformTools = require('bencoding.android.tools').createPlatform(); | |
var wasInForeGround = true; | |
//to be executed on every activity staus change | |
//check if it's passing from foreground to background or viceversa | |
function checkStatusSwitch() { | |
var isInForeground = platformTools.isInForeground(); | |
if (wasInForeGround !== isInForeground) { | |
Ti.App.fireEvent(isInForeground ? 'resume' : 'paused'); | |
wasInForeGround = isInForeground; | |
} | |
} | |
var win = Ti.UI.createWindow({}); | |
win.addEventListener("open", function(e) { | |
win.activity.addEventListener("resume", function() { | |
checkStatusSwitch(); | |
}); | |
//Notice the pause event | |
win.activity.addEventListener("pause", function() { | |
checkStatusSwitch(); | |
}); | |
}); | |
//Now works perfectly | |
Ti.App.addEventListener('resume',function(){ | |
}) | |
Ti.App.addEventListener('paused',function(){ | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment