I want my app to do something when it comes form it's background state to the active state. I understand according the cordova documentation I can do this with the code below and this is working.
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
}
// Handle the resume event
//
function onResume() {
}
My app is build with Ionic and the downside of using the code above is that it only work outside my app module, so I can't trigger functions inside my app module. I found a few code example on how it should work inside my app module, but non of them are working. See some examples below.
$ionicPlatform.on('resume', function(){
// rock on
});
/
ionic.Platform.ready(function() {
ionic.on('resume', function(){
//rock on
}, element);
});
/
$ionicPlatform.ready(function () {
document.addEventListener("deviceReady", function () {
document.addEventListener("resume", function () {
$timeout(function () {
//rock on
}, 0);
}, false);
});
});
Am I doing something wrong am I forgetting something, I hope someone can help me with this.
Thanks!!
For the ionic you try the following code, hopes it helps to you
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
document.addEventListener("pause", function() {
//code for action on pause
}, false);
document.addEventListener("resume", function() {
//code for action on resume
}, false);
});
We can use the $ionicPlatform to listen the resume event of an ionic application. This event fires once the application resumes.
$ionicPlatform.on("resume", function (event) {
// will execute when device resume.
});
Have a look at CodeExpertz for example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With