Coutdown Timer and screen off problem


#1

Hi guys,

I have a countdown timer in a view that lauch a sound when it ends. But if the screen is off, the countdown is paused. I have the view in cache = false but it’s not work.

I have this code : (at the end of countdown, i’m redirect on “finish.html”).

controller('TimerCtrl', function($scope,$timeout,$state) {
if (window.plugins !== undefined) {
	window.plugins.insomnia.keepAwake();
	window.plugins.backgroundMode.enable();
}
$scope.counter = parseFloat(window.localStorage['timer']); //oeufs à la coque basique
var mytimeout = null;
$scope.onTimeout = function() {
    if($scope.counter ===  0) {
        $scope.$broadcast('timer-stopped', 0);
        $timeout.cancel(mytimeout);
        return;
    }
    $scope.counter--;
    mytimeout = $timeout($scope.onTimeout, 1000);
};
mytimeout = $timeout($scope.onTimeout, 1000);
$scope.$on('timer-stopped', function(event, remaining) {
    if(remaining === 0) {
		$state.go('finish');
    }
});
  $scope.stop = function() {
	$state.go('home');
  }

})


#2

If the screen is off every background processes in your app gets paused ;). Like your app is in background.

Try something like that:


#3

Yes i have installed this plugin and activate on the controller like that :

	if (window.plugins !== undefined) {
	window.plugins.insomnia.keepAwake();
	window.plugins.backgroundMode.enable();
}

And i have the notification on my screen (android) :
“App is running in background”

But it’s not work :confused: