Last active
October 25, 2018 18:40
-
-
Save etruta/80a871912e69865c7bf0 to your computer and use it in GitHub Desktop.
Titanium: Another way to handle pause and resume event 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
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!"); | |
}); |
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
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