How to detect when the user leaves the app (temporarily)?

You can also use these events;

$document.addEventListener('resume', function() {
    $rootScope.$broadcast('onResume');
  });
  $document.addEventListener('pause', function() {
    $rootScope.$broadcast('onPause');
  });