Skip to content

Instantly share code, notes, and snippets.

@etruta
Last active October 25, 2018 18:40
Show Gist options
  • Save etruta/80a871912e69865c7bf0 to your computer and use it in GitHub Desktop.
Save etruta/80a871912e69865c7bf0 to your computer and use it in GitHub Desktop.
Titanium: Another way to handle pause and resume event for android
Alloy.Globals.wasInForeGround = true;
if(OS_ANDROID) {
var androidServiceIntent = Ti.Android.createServiceIntent({ url: "foreground.service.js" });
androidServiceIntent.putExtra('interval', 3000);
Ti.Android.startService(androidServiceIntent);
}
Ti.App.addEventListener('resumed', function(e) {
Ti.API.log("RESUMED YEAH!");
});
Ti.App.addEventListener('paused', function(e) {
Ti.API.log("PAUSED YEAH!");
});
var service = Ti.Android.currentService;
var intent = service.getIntent();
var platformTools = require('bencoding.android.tools').createPlatform();
var isInForeground = platformTools.isInForeground();
if (Alloy.Globals.wasInForeGround !== isInForeground) {
Ti.App.fireEvent(isInForeground ? 'resumed' : 'paused');
Alloy.Globals.wasInForeGround = isInForeground;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment