Pause and resume event are both fired at the same time

I’m using the resume and pause events from ionic. But I have the problem, that both events are fired at the end of the pause.
I receive the pause event only some miliseconds before the resume event.

Here is my configuration:

document.addEventListener("pause", function(){
    console.log("APP PAUSE");

document.addEventListener("resume", function(){
    console.log("APP RESUME");

***..two of my results:***
"APP PAUSE","2015-07-09 16:39:31.389000"
"APP RESUME","2015-07-09 16:39:31.392000"

"APP PAUSE","2015-07-09 16:41:29.437000"
"APP RESUME","2015-07-09 16:41:29.440000"

Could it be that i miss something or has anybody the same issue?
I expected that the pause event is fired at the begin of the pause and not at the end :pensive:
Or did I missunderstood that :smile:

Thanks to anybody for some helpfull answer.

Try wrapping your event listeners around an $ionicPlatform.ready

.run(function($ionicPlatform, $rootScope) {
    	$ionicPlatform.ready(function() {	
    		document.addEventListener("deviceready", onDeviceReady, false);

    	function onDeviceReady(){
    		document.addEventListener("pause", function(){
                         console.log("APP PAUSE");


@delta98: Thanks for your suggestion.

Unfortunately the functions are already wrapped by a $ionicPlatform.ready function.

But I have found the problem. It was in config.xml.

<preference name="KeepRunning" value="false"/>

I changed false to true and now it works as expected.

Good news, might be worth showing the full code next time too, so you don’t get bad suggestions :smile: